mise a jour
This commit is contained in:
16
frontend/src/hooks/useHandleAuthError.js
Normal file
16
frontend/src/hooks/useHandleAuthError.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
|
||||
export function useHandleAuthError() {
|
||||
const { logout } = useAuth()
|
||||
const navigate = useNavigate()
|
||||
|
||||
return function handleAuthError(err) {
|
||||
if (err.status === 401) {
|
||||
logout()
|
||||
navigate('/connexion')
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user