fix path error

This commit is contained in:
xion 2025-03-30 00:36:11 +08:00
parent 80d16b5f76
commit 83a018c183

View File

@ -15,10 +15,12 @@ export const createCookie = (token: any, ctx: any) => {
//TODO, 获取访问的 hostname 如果访问的和 domain 的不一致也创建cookie //TODO, 获取访问的 hostname 如果访问的和 domain 的不一致也创建cookie
const browser = ctx.req.headers['user-agent']; const browser = ctx.req.headers['user-agent'];
const isBrowser = browser.includes('Mozilla'); // 浏览器 const isBrowser = browser.includes('Mozilla'); // 浏览器
console.log('createCookie', token, ctx.res.cookie, 'isBrowser', isBrowser);
if (isBrowser && ctx.res.cookie) { if (isBrowser && ctx.res.cookie) {
ctx.res.cookie('token', token.accessToken || token?.token, { ctx.res.cookie('token', token.accessToken || token?.token, {
maxAge: 7 * 24 * 60 * 60 * 1000, // 过期时间, 设置7天 maxAge: 7 * 24 * 60 * 60 * 1000, // 过期时间, 设置7天
domain, domain,
path: '/',
sameSite: 'lax', sameSite: 'lax',
httpOnly: true, httpOnly: true,
}); });
@ -158,10 +160,17 @@ app
key: 'logout', key: 'logout',
}) })
.define(async (ctx) => { .define(async (ctx) => {
const token = ctx.query?.token;
const { tokens = [] } = ctx.query?.data || {}; const { tokens = [] } = ctx.query?.data || {};
clearCookie(ctx); clearCookie(ctx);
for (const token of tokens) { let needDelTokens = Array.from(new Set([...tokens, token].filter(Boolean)));
for (const token of needDelTokens) {
try {
await User.oauth.delToken(token); await User.oauth.delToken(token);
} catch (e) {
// console.log('logout error', e);
console.log('error token is has been deleted', token);
}
} }
ctx.body = { ctx.body = {
code: 200, code: 200,