From 8e4c6e78c73d1d8cecdfd4d5745fb09c6d4b0576 Mon Sep 17 00:00:00 2001 From: NFish Date: Fri, 1 Nov 2024 15:49:33 +0800 Subject: [PATCH] fix: redirect to the signin page if no access_token found --- web/app/components/swr-initor.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/web/app/components/swr-initor.tsx b/web/app/components/swr-initor.tsx index 5ee06fc2e8..80f1b12ed8 100644 --- a/web/app/components/swr-initor.tsx +++ b/web/app/components/swr-initor.tsx @@ -14,6 +14,10 @@ const SwrInitor = ({ }: SwrInitorProps) => { const router = useRouter() const searchParams = useSearchParams() + const consoleToken = decodeURIComponent(searchParams.get('access_token') || '') + const refreshToken = decodeURIComponent(searchParams.get('refresh_token') || '') + const consoleTokenFromLocalStorage = localStorage?.getItem('console_token') + const refreshTokenFromLocalStorage = localStorage?.getItem('refresh_token') const pathname = usePathname() const [init, setInit] = useState(false) @@ -43,9 +47,11 @@ const SwrInitor = ({ router.replace('/install') return } + if (!((consoleToken && refreshToken) || (consoleTokenFromLocalStorage && refreshTokenFromLocalStorage))) { + router.replace('/signin') + return + } if (searchParams.has('access_token') || searchParams.has('refresh_token')) { - const consoleToken = decodeURIComponent(searchParams.get('access_token') || '') - const refreshToken = decodeURIComponent(searchParams.get('refresh_token') || '') consoleToken && localStorage.setItem('console_token', consoleToken) refreshToken && localStorage.setItem('refresh_token', refreshToken) router.replace(pathname)