mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
fix: Correction des Protected Routes avec multi role
This commit is contained in:
@ -1,13 +1,20 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEstablishment } from '@/context/EstablishmentContext';
|
||||
import { FE_USERS_LOGIN_URL,getRedirectUrlFromRole } from '@/utils/Url';
|
||||
import { FE_USERS_LOGIN_URL, getRedirectUrlFromRole } from '@/utils/Url';
|
||||
|
||||
const ProtectedRoute = ({ children, requiredRight }) => {
|
||||
|
||||
const { user, profileRole } = useEstablishment();
|
||||
const router = useRouter();
|
||||
const hasRequiredRight = (profileRole === requiredRight);
|
||||
let hasRequiredRight = false;
|
||||
|
||||
if(requiredRight && Array.isArray(requiredRight) ){
|
||||
// Vérifier si l'utilisateur a le droit requis
|
||||
hasRequiredRight = requiredRight.some((right) => profileRole === right);
|
||||
}else{
|
||||
hasRequiredRight = (profileRole === requiredRight);
|
||||
}
|
||||
|
||||
// Vérifier si l'utilisateur a au moins un rôle correspondant au requiredRight
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user