feat(auth): 生产环境支持http

This commit is contained in:
liuyonghe0111 2025-12-19 15:22:35 +08:00
parent 35d63bdd64
commit 8fe37d8814
3 changed files with 33 additions and 34 deletions

View File

@ -19,7 +19,7 @@ export default async function Page({ params }: { params: Promise<{ id: string }>
<IconButton variant="tertiary" size="large" iconfont="icon-Like" />
</div>
{/* 内容区 */}
<div className="mx-auto flex-1 w-full">
<div className="mx-auto flex-1 overflow-auto w-full">
<header className="flex items-end gap-10 justify-between">
<div className="flex flex-1 sm:flex-row flex-col gap-6 items-center sm:items-end">
<Avatar className="size-32">

View File

@ -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() {

View File

@ -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') {
// 设置cookie30天过期
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 = {
// 设置cookie365天过期设备ID应该长期保存
Cookies.set(DEVICE_ID_COOKIE_NAME, deviceId, {
expires: 365,
secure: process.env.NODE_ENV === 'production',
secure: false,
sameSite: 'lax',
});
}