From 5e6be249d6d72c4d17bb748f85a375a6921987dc Mon Sep 17 00:00:00 2001 From: elcharitas Date: Tue, 3 Dec 2024 05:56:11 +0100 Subject: [PATCH] fix: random auth related blank screens --- packages/frontend/src/api/hooks/useAppInit.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/frontend/src/api/hooks/useAppInit.ts b/packages/frontend/src/api/hooks/useAppInit.ts index de676d36d..3ab49a31b 100644 --- a/packages/frontend/src/api/hooks/useAppInit.ts +++ b/packages/frontend/src/api/hooks/useAppInit.ts @@ -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(); + } };