DONE: first init

This commit is contained in:
ISMAIL MASSERAN
2026-07-20 16:10:22 +08:00
commit 3189e3a1e3
272 changed files with 48853 additions and 0 deletions
@@ -0,0 +1,30 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
export default function AuthGuard({ children, roles }) {
const navigate = useNavigate();
useEffect(() => {
const storedUserData = localStorage.getItem('userData');
const user = storedUserData ? JSON.parse(storedUserData) : null;
if (!user) {
navigate('/login');
return;
}
const hasNecessaryRole = roles.some(role => user.roles.find(userRole => userRole === role));
if (!hasNecessaryRole) {
navigate('/');
return;
}
}, []);
return (
<>
{ children }
</>
);
}