From 8fe37d8814537c26939a0bbbd4f32cacd48cc29b Mon Sep 17 00:00:00 2001
From: liuyonghe0111 <1763195287@qq.com>
Date: Fri, 19 Dec 2025 15:22:35 +0800
Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E7=94=9F=E4=BA=A7=E7=8E=AF?=
=?UTF-8?q?=E5=A2=83=E6=94=AF=E6=8C=81http?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/app/(main)/character/[id]/page.tsx | 2 +-
src/hooks/auth.ts | 54 +++++++++++++-------------
src/lib/auth/token.ts | 11 +++---
3 files changed, 33 insertions(+), 34 deletions(-)
diff --git a/src/app/(main)/character/[id]/page.tsx b/src/app/(main)/character/[id]/page.tsx
index 1b3dc2d..e25c2c9 100644
--- a/src/app/(main)/character/[id]/page.tsx
+++ b/src/app/(main)/character/[id]/page.tsx
@@ -19,7 +19,7 @@ export default async function Page({ params }: { params: Promise<{ id: string }>
{/* 内容区 */}
-
+
diff --git a/src/hooks/auth.ts b/src/hooks/auth.ts
index 0b96f55..fc6d897 100644
--- a/src/hooks/auth.ts
+++ b/src/hooks/auth.ts
@@ -129,34 +129,34 @@ export function useDeleteUser() {
}
// 注册功能暂未实现,保留接口定义
-export function useRegister() {
- const queryClient = useQueryClient();
+// export function useRegister() {
+// const queryClient = useQueryClient();
- return useMutation({
- mutationFn: (data: any) => {
- // TODO: 实现注册接口
- throw new Error('注册功能暂未实现');
- },
- onSuccess: (response: LoginResponse) => {
- // 注册成功后自动登录
- tokenManager.setToken(response.token);
- toast.success('Successful registration!');
- queryClient.invalidateQueries({
- queryKey: authKeys.currentUser(),
- });
- },
- onError: (error: ApiError) => {
- console.error('注册失败:', {
- errorCode: error.errorCode,
- errorMsg: error.errorMsg,
- traceId: error.traceId,
- });
- toast.error('Registration failed.', {
- description: error.errorMsg || '请稍后重试',
- });
- },
- });
-}
+// return useMutation({
+// mutationFn: (data: any) => {
+// // TODO: 实现注册接口
+// throw new Error('注册功能暂未实现');
+// },
+// onSuccess: (response: LoginResponse) => {
+// // 注册成功后自动登录
+// tokenManager.setToken(response.token);
+// toast.success('Successful registration!');
+// queryClient.invalidateQueries({
+// queryKey: authKeys.currentUser(),
+// });
+// },
+// onError: (error: ApiError) => {
+// console.error('注册失败:', {
+// errorCode: error.errorCode,
+// errorMsg: error.errorMsg,
+// traceId: error.traceId,
+// });
+// toast.error('Registration failed.', {
+// description: error.errorMsg || '请稍后重试',
+// });
+// },
+// });
+// }
// 检查是否已登录的hook
export function useIsAuthenticated() {
diff --git a/src/lib/auth/token.ts b/src/lib/auth/token.ts
index a660777..e37ce2f 100644
--- a/src/lib/auth/token.ts
+++ b/src/lib/auth/token.ts
@@ -10,8 +10,8 @@ function generateDeviceId(): string {
const browserInfo =
typeof window !== 'undefined'
? `${window.navigator.userAgent}${window.screen.width}${window.screen.height}`
- .replace(/\s/g, '')
- .substring(0, 10)
+ .replace(/\s/g, '')
+ .substring(0, 10)
: 'server';
return `did_${timestamp}_${randomStr}_${browserInfo}`.toLowerCase();
@@ -82,10 +82,9 @@ export const tokenManager = {
// 设置token
setToken: (token: string): void => {
if (typeof window !== 'undefined') {
- // 设置cookie,30天过期
Cookies.set(TOKEN_COOKIE_NAME, token, {
- expires: 30,
- secure: process.env.NODE_ENV === 'production',
+ expires: 365,
+ secure: false,
sameSite: 'lax',
});
}
@@ -97,7 +96,7 @@ export const tokenManager = {
// 设置cookie,365天过期(设备ID应该长期保存)
Cookies.set(DEVICE_ID_COOKIE_NAME, deviceId, {
expires: 365,
- secure: process.env.NODE_ENV === 'production',
+ secure: false,
sameSite: 'lax',
});
}