fix auth redirect
This commit is contained in:
@@ -27,11 +27,12 @@ export const AuthUserProvider = ({children}: PropsWithChildren) => {
|
||||
try {
|
||||
const res = await axios.get('/api/user')
|
||||
setAuthUser(res.data)
|
||||
} catch (e) {
|
||||
} catch (error) {
|
||||
// @ts-expect-error check axios response status
|
||||
if (e.response.status === 401) {
|
||||
if (error.response.status === 401) {
|
||||
console.info('no user login')
|
||||
if (window.location.pathname !== '/connexion') {
|
||||
let url = window.location.pathname.split('/')[1]
|
||||
if (!['connexion', 'changer-le-mot-de-passe'].includes(url)) {
|
||||
window.location.href = '/connexion'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user