Skip to content

Commit

Permalink
refactor: split fetching me function
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Nov 6, 2024
1 parent 034c147 commit 47ce415
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions client/features/auth/AuthLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 47ce415

Please sign in to comment.