File tree Expand file tree Collapse file tree 1 file changed +34
-18
lines changed Expand file tree Collapse file tree 1 file changed +34
-18
lines changed Original file line number Diff line number Diff line change @@ -28,9 +28,7 @@ module.exports = async function checkAuth(ctx, next) {
28
28
if ( duserStr ) {
29
29
try {
30
30
const duser = JSON . parse ( duserStr ) ;
31
-
32
31
ctx . session . user = duser ;
33
-
34
32
await next ( ) ;
35
33
return ;
36
34
} catch ( err ) {
@@ -67,22 +65,6 @@ module.exports = async function checkAuth(ctx, next) {
67
65
68
66
// user.login 存在表示登录成功
69
67
if ( user . login ) {
70
- ctx . cookies . set (
71
- "token" ,
72
- encrypt (
73
- Buffer . from (
74
- JSON . stringify ( {
75
- ...user ,
76
- pay : true ,
77
- } ) ,
78
- "utf8"
79
- )
80
- ) ,
81
- {
82
- httpOnly : false ,
83
- expires : new Date ( 24 * 60 * 60 * 1000 + Date . now ( ) ) ,
84
- }
85
- ) ;
86
68
// 付费用户
87
69
if ( db . find ( ( q ) => q . login === user . login ) ) {
88
70
// TODO: 如果不在组织中,自动邀请进 Github 组织
@@ -93,11 +75,45 @@ module.exports = async function checkAuth(ctx, next) {
93
75
...user ,
94
76
pay : true ,
95
77
} ;
78
+
79
+ ctx . cookies . set (
80
+ "token" ,
81
+ encrypt (
82
+ Buffer . from (
83
+ JSON . stringify ( {
84
+ ...user ,
85
+ pay : true ,
86
+ } ) ,
87
+ "utf8"
88
+ )
89
+ ) ,
90
+ {
91
+ httpOnly : false ,
92
+ expires : new Date ( 24 * 60 * 60 * 1000 + Date . now ( ) ) ,
93
+ }
94
+ ) ;
96
95
} else {
97
96
ctx . session . user = {
98
97
...user ,
99
98
pay : false ,
100
99
} ;
100
+
101
+ ctx . cookies . set (
102
+ "token" ,
103
+ encrypt (
104
+ Buffer . from (
105
+ JSON . stringify ( {
106
+ ...user ,
107
+ pay : false ,
108
+ } ) ,
109
+ "utf8"
110
+ )
111
+ ) ,
112
+ {
113
+ httpOnly : false ,
114
+ expires : new Date ( 24 * 60 * 60 * 1000 + Date . now ( ) ) ,
115
+ }
116
+ ) ;
101
117
}
102
118
}
103
119
You can’t perform that action at this time.
0 commit comments