diff --git a/client/features/auth/AuthLoader.tsx b/client/features/auth/AuthLoader.tsx index 56a3fd5..7c7e6f8 100644 --- a/client/features/auth/AuthLoader.tsx +++ b/client/features/auth/AuthLoader.tsx @@ -12,6 +12,10 @@ export const AuthLoader = () => { const { user, setUser } = useUser(); const { setLoading } = useLoading(); const { setAlert } = useAlert(); + const fetchMe = useCallback( + () => apiClient.private.me.$get().catch(catchApiErr).then(setUser), + [setUser], + ); const updateCookie = useCallback(async () => { const tokens = await fetchAuthSession() .then((e) => e.tokens) @@ -25,14 +29,12 @@ export const AuthLoader = () => { }) .catch(catchApiErr); - if (result?.status === 'success') { - await apiClient.private.me.$get().catch(catchApiErr).then(setUser); - } - }, [setUser]); + if (result?.status === 'success') await fetchMe(); + }, [setUser, fetchMe]); useEffect(() => { - updateCookie(); - }, [updateCookie]); + fetchMe(); + }, [fetchMe]); useEffect(() => { // eslint-disable-next-line complexity