Skip to content

Commit

Permalink
Fix : session update
Browse files Browse the repository at this point in the history
  • Loading branch information
oikkoikk committed Oct 8, 2023
1 parent e88b858 commit 8adfbb3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 8adfbb3

Please sign in to comment.