Skip to content

Commit 79950ac

Browse files
author
lucifer
committed
fix: 登录成功都需要记录cookie
1 parent f0b3791 commit 79950ac

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

middleware/passport.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,23 @@ module.exports = async function checkAuth(ctx, next) {
5151
Authorization: `token ${access_token}`,
5252
},
5353
}).then((res) => res.json());
54-
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+
);
5570
if (db.find((q) => q.login === user.login)) {
56-
ctx.cookies.set(
57-
"token",
58-
encrypt(
59-
Buffer.from(
60-
JSON.stringify({
61-
...user,
62-
pay: true,
63-
}),
64-
"utf8"
65-
)
66-
),
67-
{
68-
httpOnly: false,
69-
expires: new Date(24 * 60 * 60 * 1000 + Date.now()),
70-
}
71-
);
72-
7371
ctx.session.user = {
7472
...user,
7573
pay: true,

0 commit comments

Comments
 (0)