From c12cb2913a4d508f5d2c77037b73d28f363689bc Mon Sep 17 00:00:00 2001 From: NFish Date: Sat, 12 Oct 2024 14:08:51 +0800 Subject: [PATCH] fix: save access_token and refresh_token to the localStorage after login success --- web/app/components/swr-initor.tsx | 5 ++++- web/app/signin/normalForm.tsx | 2 ++ web/app/signin/userSSOForm.tsx | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/web/app/components/swr-initor.tsx b/web/app/components/swr-initor.tsx index 52d4ec307e..d26e04e68e 100644 --- a/web/app/components/swr-initor.tsx +++ b/web/app/components/swr-initor.tsx @@ -29,8 +29,11 @@ const SwrInitor = ({ if (consoleTokenFromLocalStorage && refreshTokenFromLocalStorage) getNewAccessToken(consoleTokenFromLocalStorage, refreshTokenFromLocalStorage) - if (consoleToken && refreshToken) + if (consoleToken && refreshToken) { + localStorage.setItem('console_token', consoleToken) + localStorage.setItem('refresh_token', refreshToken) getNewAccessToken(consoleToken, refreshToken) + } router.replace('/apps', { forceOptimisticNavigation: false } as any) setInit(true) diff --git a/web/app/signin/normalForm.tsx b/web/app/signin/normalForm.tsx index 2060ba490c..0ae4eb1f43 100644 --- a/web/app/signin/normalForm.tsx +++ b/web/app/signin/normalForm.tsx @@ -97,6 +97,8 @@ const NormalForm = () => { }, }) if (res.result === 'success') { + localStorage.setItem('console_token', res.data.access_token) + localStorage.setItem('refresh_token', res.data.refresh_token) getNewAccessToken(res.data.access_token, res.data.refresh_token) router.replace('/apps') } diff --git a/web/app/signin/userSSOForm.tsx b/web/app/signin/userSSOForm.tsx index e1db35fae2..e4b61413bc 100644 --- a/web/app/signin/userSSOForm.tsx +++ b/web/app/signin/userSSOForm.tsx @@ -29,6 +29,8 @@ const UserSSOForm: FC = ({ useEffect(() => { if (refreshToken && consoleToken) { + localStorage.setItem('console_token', consoleToken) + localStorage.setItem('refresh_token', refreshToken) getNewAccessToken(consoleToken, refreshToken) router.replace('/apps') }