From a522ea4ba2f3131215b75498dde4efd40181e9eb Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Wed, 5 Jun 2024 12:48:16 +0800 Subject: [PATCH] fix/prevent logout in login routes (#1889) --- src/contexts/LoginContext.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/contexts/LoginContext.tsx b/src/contexts/LoginContext.tsx index 65e0c2297..44d315af4 100644 --- a/src/contexts/LoginContext.tsx +++ b/src/contexts/LoginContext.tsx @@ -7,6 +7,7 @@ import { useCallback, useState, } from "react" +import { useLocation } from "react-router-dom" import { LOCAL_STORAGE_KEYS } from "constants/localStorage" @@ -15,6 +16,7 @@ import { useLocalStorage } from "hooks/useLocalStorage" import { LoggedInUser, UserType, UserTypes } from "types/user" const { REACT_APP_BACKEND_URL_V2: BACKEND_URL } = process.env +const LOGIN_PATHS = ["/", "/sgid-callback"] interface LoginContextProps extends LoggedInUser { isLoading: boolean @@ -36,6 +38,7 @@ const useLoginContext = (): LoginContextProps => { const LoginProvider = ({ children, }: PropsWithChildren>): JSX.Element => { + const { pathname } = useLocation() const [, , removeSites] = useLocalStorage( LOCAL_STORAGE_KEYS.SitesIsPrivate, false @@ -69,7 +72,11 @@ const LoginProvider = ({ return response }, async (error) => { - if (error.response && error.response.status === 401) { + if ( + error.response && + error.response.status === 401 && + !LOGIN_PATHS.includes(pathname) + ) { await logout() } setIsLoading(false)