Skip to content

Commit 2bc02f2

Browse files
author
lucifer
committed
fix: 付费逻辑
1 parent 7971029 commit 2bc02f2

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

middleware/passport.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ module.exports = async function checkAuth(ctx, next) {
2828
if (duserStr) {
2929
try {
3030
const duser = JSON.parse(duserStr);
31-
3231
ctx.session.user = duser;
33-
3432
await next();
3533
return;
3634
} catch (err) {
@@ -67,22 +65,6 @@ module.exports = async function checkAuth(ctx, next) {
6765

6866
// user.login 存在表示登录成功
6967
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-
);
8668
// 付费用户
8769
if (db.find((q) => q.login === user.login)) {
8870
// TODO: 如果不在组织中,自动邀请进 Github 组织
@@ -93,11 +75,45 @@ module.exports = async function checkAuth(ctx, next) {
9375
...user,
9476
pay: true,
9577
};
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+
);
9695
} else {
9796
ctx.session.user = {
9897
...user,
9998
pay: false,
10099
};
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+
);
101117
}
102118
}
103119

0 commit comments

Comments
 (0)