From 8adfbb34227635f29a762ed04759ca0c46bfeb63 Mon Sep 17 00:00:00 2001 From: oikkoikk Date: Mon, 9 Oct 2023 02:06:37 +0900 Subject: [PATCH] Fix : session update --- src/hooks/useAuth.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts index ea0a6e6..005f9b3 100644 --- a/src/hooks/useAuth.ts +++ b/src/hooks/useAuth.ts @@ -15,25 +15,25 @@ export default function useAuth() { const refreshToken = { refresh_token: session?.refresh_token ?? '' }; const silentRefresh = async () => { - const response = await fetchUserAuthWithRefreshToken(refreshToken) - .then(async (res) => { - await update(res); - return res; - }) - .catch(async () => { + const response = await fetchUserAuthWithRefreshToken(refreshToken).catch( + async () => { await logout(); setErrorToast(new Error(ErrorMessage.REFRESH)); - }); - + return null; + } + ); return response; }; - useQuery([QueryKeys.REFRESH], () => silentRefresh(), { + useQuery([QueryKeys.REFRESH], silentRefresh, { enabled: !!session, refetchInterval: refreshInterval, refetchOnMount: false, refetchOnWindowFocus: false, - refetchIntervalInBackground: true + refetchIntervalInBackground: true, + onSuccess: async (data) => { + await update(data); + } }); const login = async (googleResponse: GoogleLoginCredential) => {