Skip to content

Commit

Permalink
auth update
Browse files Browse the repository at this point in the history
  • Loading branch information
danicc097 committed Aug 28, 2024
1 parent 75ee974 commit f6ebf61
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions frontend/src/hooks/auth/useAuthenticatedUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)
Expand Down Expand Up @@ -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])

Check warning on line 72 in frontend/src/hooks/auth/useAuthenticatedUser.tsx

View workflow job for this annotation

GitHub Actions / run

React Hook useEffect has missing dependencies: 'currentUser' and 'renders'. Either include them or remove the dependency array

const user = currentUser.data

Expand Down

0 comments on commit f6ebf61

Please sign in to comment.