From 445c27c69e3e46c73e273eda9d0e02ad5a022d4b Mon Sep 17 00:00:00 2001 From: mackt <1033530438@qq.com> Date: Fri, 26 Apr 2024 22:19:40 +0500 Subject: [PATCH] fiex(Login): redirect --- src/components/Login/LoginForm.tsx | 2 +- src/hooks/useLoginRedirect.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Login/LoginForm.tsx b/src/components/Login/LoginForm.tsx index 08f234a..c65c154 100644 --- a/src/components/Login/LoginForm.tsx +++ b/src/components/Login/LoginForm.tsx @@ -68,7 +68,7 @@ export default function LoginForm({ className }: { className?: string }) { if (result.code === 200) { setShowLogin(false); await getUserInfo(); - router.replace(redirect); + if (redirect) router.replace(redirect); } else { setErrorText(result.message); setBtnLoading(false); diff --git a/src/hooks/useLoginRedirect.ts b/src/hooks/useLoginRedirect.ts index fd0e82a..a014717 100644 --- a/src/hooks/useLoginRedirect.ts +++ b/src/hooks/useLoginRedirect.ts @@ -1,8 +1,8 @@ import { useSearchParams } from 'next/navigation'; -export const useLoginRedirect = () => { +export const useLoginRedirect: () => string | null = () => { const searchParams = useSearchParams(); const redirect = searchParams.get('redirect'); - if (!redirect) return '/'; + if (!redirect) return null; return redirect; };