Skip to content

Commit 7cde1e8

Browse files
author
lucifer
committed
feat: 付费后无需清 cookie
1 parent ac9528f commit 7cde1e8

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

config/index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,22 +300,26 @@ RealDuxy
300300
NealChristmas
301301
zibinanhai
302302
flashyy
303-
NorthSeacoder`),
303+
NorthSeacoder`),
304304
];
305305

306+
const userList = [
307+
{
308+
login: "azl397985856",
309+
},
310+
].concat(
311+
tobeIdentified.map((name) => ({
312+
login: name,
313+
}))
314+
);
315+
306316
module.exports = {
307317
owner: "leetcode-pp",
308318
repo: "91alg-4",
309319
startTime: startTime.getTime(),
310320
secret: process.env.secret,
311321
clientId: "c16b80e7b58a5a007157",
312-
db: [
313-
{
314-
login: "azl397985856",
315-
},
316-
].concat(
317-
tobeIdentified.map((name) => ({
318-
login: name,
319-
}))
320-
),
322+
db: userList.reduce((acc, curr) => {
323+
acc[curr.login] = curr;
324+
}, {}),
321325
};

middleware/passport.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ module.exports = async function checkAuth(ctx, next) {
1919
if (duserStr) {
2020
try {
2121
const duser = JSON.parse(duserStr);
22-
ctx.session.user = duser;
22+
ctx.session.user = {
23+
...duser,
24+
pay: !!db[duser.login],
25+
};
2326
await next();
2427
return;
2528
} catch (err) {
@@ -59,7 +62,7 @@ module.exports = async function checkAuth(ctx, next) {
5962
// user.login 存在表示登录成功
6063
if (user.login) {
6164
// 付费用户
62-
const pay = !!db.find((q) => q.login === user.login);
65+
const pay = !!db[user.login];
6366
const u = {
6467
...user,
6568
pay,

0 commit comments

Comments
 (0)