mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
refactor: gestion des erreurs
This commit is contained in:
@ -4,7 +4,7 @@ import { useSession } from 'next-auth/react';
|
||||
import Loader from '@/components/Loader'; // Importez le composant Loader
|
||||
import { FE_USERS_LOGIN_URL } from '@/utils/Url';
|
||||
|
||||
const ProtectedRoute = ({ children }) => {
|
||||
const ProtectedRoute = ({ children, requiredRight }) => {
|
||||
const { data: session, status } = useSession({
|
||||
required: true,
|
||||
onUnauthenticated() {
|
||||
@ -18,7 +18,13 @@ const ProtectedRoute = ({ children }) => {
|
||||
return <Loader />;
|
||||
}
|
||||
|
||||
// Autoriser l'affichage si authentifié
|
||||
// Vérifier le rôle de l'utilisateur
|
||||
if (session && requiredRight && session.user.droit !== requiredRight) {
|
||||
router.push(`${FE_USERS_LOGIN_URL}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Autoriser l'affichage si authentifié et rôle correct
|
||||
return session ? children : null;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user