changement
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Navigate } from 'react-router-dom'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
import { homeFor, INITIAL_PASSWORD_PATH } from '../config/roles'
|
||||
|
||||
export default function ProtectedRoute({ children, roles }) {
|
||||
const { user } = useAuth()
|
||||
@@ -8,9 +9,14 @@ export default function ProtectedRoute({ children, roles }) {
|
||||
return <Navigate to="/connexion" replace />
|
||||
}
|
||||
|
||||
// Mot de passe provisoire : aucune page protégée tant qu'il n'est pas
|
||||
// remplacé (le backend refuse de toute façon les appels à l'API).
|
||||
if (user.mustChangePassword) {
|
||||
return <Navigate to={INITIAL_PASSWORD_PATH} replace />
|
||||
}
|
||||
|
||||
if (roles && !roles.includes(user.role)) {
|
||||
const redirects = { ADMIN: '/admin', EMPLOYEE: '/employe', CLIENT: '/mes-gains' }
|
||||
return <Navigate to={redirects[user.role] || '/connexion'} replace />
|
||||
return <Navigate to={homeFor(user)} replace />
|
||||
}
|
||||
|
||||
return children
|
||||
|
||||
Reference in New Issue
Block a user