Skip to content

Commit ba6ae5f

Browse files
author
lucifer
committed
fix: login
1 parent 79950ac commit ba6ae5f

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

middleware/passport.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,26 @@ module.exports = async function checkAuth(ctx, next) {
5151
Authorization: `token ${access_token}`,
5252
},
5353
}).then((res) => res.json());
54-
ctx.cookies.set(
55-
"token",
56-
encrypt(
57-
Buffer.from(
58-
JSON.stringify({
59-
...user,
60-
pay: true,
61-
}),
62-
"utf8"
63-
)
64-
),
65-
{
66-
httpOnly: false,
67-
expires: new Date(24 * 60 * 60 * 1000 + Date.now()),
68-
}
69-
);
54+
55+
// user.login 存在表示登录成功
56+
if (user.login) {
57+
ctx.cookies.set(
58+
"token",
59+
encrypt(
60+
Buffer.from(
61+
JSON.stringify({
62+
...user,
63+
pay: true,
64+
}),
65+
"utf8"
66+
)
67+
),
68+
{
69+
httpOnly: false,
70+
expires: new Date(24 * 60 * 60 * 1000 + Date.now()),
71+
}
72+
);
73+
}
7074
if (db.find((q) => q.login === user.login)) {
7175
ctx.session.user = {
7276
...user,

0 commit comments

Comments
 (0)