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" /> <IconButton variant="tertiary" size="large" iconfont="icon-Like" />
</div> </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"> <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"> <div className="flex flex-1 sm:flex-row flex-col gap-6 items-center sm:items-end">
<Avatar className="size-32"> <Avatar className="size-32">

View File

@ -129,34 +129,34 @@ export function useDeleteUser() {
} }
// 注册功能暂未实现,保留接口定义 // 注册功能暂未实现,保留接口定义
export function useRegister() { // export function useRegister() {
const queryClient = useQueryClient(); // const queryClient = useQueryClient();
return useMutation({ // return useMutation({
mutationFn: (data: any) => { // mutationFn: (data: any) => {
// TODO: 实现注册接口 // // TODO: 实现注册接口
throw new Error('注册功能暂未实现'); // throw new Error('注册功能暂未实现');
}, // },
onSuccess: (response: LoginResponse) => { // onSuccess: (response: LoginResponse) => {
// 注册成功后自动登录 // // 注册成功后自动登录
tokenManager.setToken(response.token); // tokenManager.setToken(response.token);
toast.success('Successful registration!'); // toast.success('Successful registration!');
queryClient.invalidateQueries({ // queryClient.invalidateQueries({
queryKey: authKeys.currentUser(), // queryKey: authKeys.currentUser(),
}); // });
}, // },
onError: (error: ApiError) => { // onError: (error: ApiError) => {
console.error('注册失败:', { // console.error('注册失败:', {
errorCode: error.errorCode, // errorCode: error.errorCode,
errorMsg: error.errorMsg, // errorMsg: error.errorMsg,
traceId: error.traceId, // traceId: error.traceId,
}); // });
toast.error('Registration failed.', { // toast.error('Registration failed.', {
description: error.errorMsg || '请稍后重试', // description: error.errorMsg || '请稍后重试',
}); // });
}, // },
}); // });
} // }
// 检查是否已登录的hook // 检查是否已登录的hook
export function useIsAuthenticated() { export function useIsAuthenticated() {

View File

@ -82,10 +82,9 @@ export const tokenManager = {
// 设置token // 设置token
setToken: (token: string): void => { setToken: (token: string): void => {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
// 设置cookie30天过期
Cookies.set(TOKEN_COOKIE_NAME, token, { Cookies.set(TOKEN_COOKIE_NAME, token, {
expires: 30, expires: 365,
secure: process.env.NODE_ENV === 'production', secure: false,
sameSite: 'lax', sameSite: 'lax',
}); });
} }
@ -97,7 +96,7 @@ export const tokenManager = {
// 设置cookie365天过期设备ID应该长期保存 // 设置cookie365天过期设备ID应该长期保存
Cookies.set(DEVICE_ID_COOKIE_NAME, deviceId, { Cookies.set(DEVICE_ID_COOKIE_NAME, deviceId, {
expires: 365, expires: 365,
secure: process.env.NODE_ENV === 'production', secure: false,
sameSite: 'lax', sameSite: 'lax',
}); });
} }