Skip to content

Commit

Permalink
Make public leaderboard less of a hack
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiash98 committed Feb 22, 2024
1 parent 5bd82ff commit 7a023db
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions frontend/src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ export function useAuth() {
fetchMeFromApi();
}, []);

/**
* List of paths that are allowed to be accessed without being logged in
*/
const allowedUnauthorizedPaths = ["/leaderboard"];

useEffect(() => {
if (!me && isLoaded) {
if (
!me &&
isLoaded &&
!allowedUnauthorizedPaths.includes(location.pathname)
) {
logout();
} else if (!!me && isLoaded && location.pathname == "/login") {
navigate("/");
Expand All @@ -26,11 +35,11 @@ export function useAuth() {
try {
const meFromApi = await fetchMe({});
setMe(meFromApi);
setIsLoaded(true);
} catch (error) {
if (location.pathname != "/leaderboard") {
navigate("/login");
}
// Its okay to fail here, user is not logged in
setMe(null);
} finally {
setIsLoaded(true);
}
}

Expand Down

0 comments on commit 7a023db

Please sign in to comment.