Skip to content

Commit

Permalink
fix/prevent logout in login routes (#1889)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderleegs authored Jun 5, 2024
1 parent b3fff05 commit a522ea4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/contexts/LoginContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useCallback,
useState,
} from "react"
import { useLocation } from "react-router-dom"

import { LOCAL_STORAGE_KEYS } from "constants/localStorage"

Expand All @@ -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
Expand All @@ -36,6 +38,7 @@ const useLoginContext = (): LoginContextProps => {
const LoginProvider = ({
children,
}: PropsWithChildren<Record<string, never>>): JSX.Element => {
const { pathname } = useLocation()
const [, , removeSites] = useLocalStorage(
LOCAL_STORAGE_KEYS.SitesIsPrivate,
false
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a522ea4

Please sign in to comment.