Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: random auth related blank screens #477

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
};
Loading