From f9777b878575220b9ba28f6faf2b3e5c7d39ab2c Mon Sep 17 00:00:00 2001 From: liuyonghe0111 <1763195287@qq.com> Date: Fri, 19 Dec 2025 15:34:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E5=AE=8C=E5=96=84=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/auth/token.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/auth/token.ts b/src/lib/auth/token.ts index e37ce2f..cedb038 100644 --- a/src/lib/auth/token.ts +++ b/src/lib/auth/token.ts @@ -17,6 +17,7 @@ function generateDeviceId(): string { return `did_${timestamp}_${randomStr}_${browserInfo}`.toLowerCase(); } +const cookieSecure = false; export const tokenManager = { // 获取token - 支持客户端和服务端 getToken: (cookieString?: string): string | null => { @@ -84,7 +85,7 @@ export const tokenManager = { if (typeof window !== 'undefined') { Cookies.set(TOKEN_COOKIE_NAME, token, { expires: 365, - secure: false, + secure: cookieSecure, sameSite: 'lax', }); } @@ -96,7 +97,7 @@ export const tokenManager = { // 设置cookie,365天过期(设备ID应该长期保存) Cookies.set(DEVICE_ID_COOKIE_NAME, deviceId, { expires: 365, - secure: false, + secure: cookieSecure, sameSite: 'lax', }); } @@ -108,7 +109,7 @@ export const tokenManager = { console.log('remove token'); // 删除cookie时需要指定与设置时相同的选项 Cookies.remove(TOKEN_COOKIE_NAME, { - secure: process.env.NODE_ENV === 'production', + secure: cookieSecure, sameSite: 'lax', path: '/', }); @@ -122,7 +123,7 @@ export const tokenManager = { clearAll: (): void => { if (typeof window !== 'undefined') { const cookieOptions = { - secure: process.env.NODE_ENV === 'production', + secure: cookieSecure, sameSite: 'lax' as const, path: '/', };