From f6ebf61c225e926158db487069c1aa49ddc64aa8 Mon Sep 17 00:00:00 2001 From: danicc097 Date: Wed, 28 Aug 2024 18:43:03 +0200 Subject: [PATCH] auth update --- frontend/src/hooks/auth/useAuthenticatedUser.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/hooks/auth/useAuthenticatedUser.tsx b/frontend/src/hooks/auth/useAuthenticatedUser.tsx index 2c709a8ca..35668c78b 100644 --- a/frontend/src/hooks/auth/useAuthenticatedUser.tsx +++ b/frontend/src/hooks/auth/useAuthenticatedUser.tsx @@ -11,6 +11,7 @@ import useRenders from 'src/hooks/utils/useRenders' import { persister } from 'src/idb' import { LOGIN_COOKIE_KEY, UI_SLICE_PERSIST_KEY, useUISlice } from 'src/slices/ui' import AxiosInterceptors from 'src/utils/axios' +import HttpStatus from 'src/utils/httpStatus' import { ToastId } from 'src/utils/toasts' import { useIsFirstRender } from 'usehooks-ts' @@ -32,9 +33,14 @@ export default function useAuthenticatedUser() { const isFirstRender = useIsFirstRender() const ui = useUISlice() const isAuthenticated = !!currentUser.data?.userID - const isAuthenticating = (currentUser.isFetching || currentUser.isRefetching) && ui.accessToken !== '' + const isAuthenticating = + (currentUser.isFetching || currentUser.isRefetching) && + ui.accessToken !== '' && + currentUser.error?.status !== HttpStatus.UNAUTHORIZED_401 // console.log({ isFirstRender }) + console.log({ isAuthenticating }) + useEffect(() => { if (mountedRef.current && isFirstRender) { // FIXME: ... one-off logic (in theory, not working) @@ -63,7 +69,7 @@ export default function useAuthenticatedUser() { return () => { AxiosInterceptors.teardownAxiosInstance(AXIOS_INSTANCE) } - }, [currentUser.data, isFirstRender, isAuthenticated, ui.accessToken, isAuthenticating, failedAuthentication]) + }, [currentUser.data, isFirstRender, isAuthenticated, ui.accessToken, failedAuthentication, mountedRef]) const user = currentUser.data