fix path error
This commit is contained in:
parent
80d16b5f76
commit
83a018c183
@ -15,10 +15,12 @@ export const createCookie = (token: any, ctx: any) => {
|
||||
//TODO, 获取访问的 hostname, 如果访问的和 domain 的不一致,也创建cookie
|
||||
const browser = ctx.req.headers['user-agent'];
|
||||
const isBrowser = browser.includes('Mozilla'); // 浏览器
|
||||
console.log('createCookie', token, ctx.res.cookie, 'isBrowser', isBrowser);
|
||||
if (isBrowser && ctx.res.cookie) {
|
||||
ctx.res.cookie('token', token.accessToken || token?.token, {
|
||||
maxAge: 7 * 24 * 60 * 60 * 1000, // 过期时间, 设置7天
|
||||
domain,
|
||||
path: '/',
|
||||
sameSite: 'lax',
|
||||
httpOnly: true,
|
||||
});
|
||||
@ -158,10 +160,17 @@ app
|
||||
key: 'logout',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const token = ctx.query?.token;
|
||||
const { tokens = [] } = ctx.query?.data || {};
|
||||
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);
|
||||
} catch (e) {
|
||||
// console.log('logout error', e);
|
||||
console.log('error token is has been deleted', token);
|
||||
}
|
||||
}
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
|
Loading…
x
Reference in New Issue
Block a user