Skip to content

Commit

Permalink
fix: random auth related blank screens (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
elcharitas authored Dec 5, 2024
1 parent 515e88d commit 206d74c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/frontend/src/api/hooks/useAppInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,27 @@ import {
useGetFeaturesQuery,
useGetSubscribedViewsQuery,
} from "src/api/services";
import * as userStore from "src/api/store/slices/user";
import { useAppDispatch } from "../store/hooks";
import { getRtkErrorCode } from "../utils/errorHandling";
import { Logger } from "../utils/logging";

export const useAppInit: () => void = () => {
/**
* Fetch the features on app load, then we rely on redux cache to
* ensure subsequent calls are cached.
*/
useGetFeaturesQuery();
const dispatch = useAppDispatch();
const { error } = useGetFeaturesQuery();
useGetSubscribedViewsQuery();

if (getRtkErrorCode(error) === 401) {
/**
* If the status check or the subscribed views endpoint gives a 401 unauthorized error,
* we need to reset the auth state and reload the app
*/
Logger.debug("App::AppRoutes: 401 received");
dispatch(userStore.resetAuthState());
location.reload();
}
};

0 comments on commit 206d74c

Please sign in to comment.