fix auth redirect

This commit is contained in:
Romulus21
2024-05-25 15:53:47 +02:00
parent 906db7a908
commit 64e99676ab
2 changed files with 7 additions and 3 deletions

View File

@@ -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'
}
}