https://dev.kronoz.win/r/marzneshin.git
1import { useAuth } from "@marzneshin/modules/auth";
2import { useNavigate } from "@tanstack/react-router";
3import { useEffect , PropsWithChildren, FC} from "react";
4
5export const SudoRoute: FC<PropsWithChildren> = ({ children }) => {
6 const { isSudo, isLoggedIn } = useAuth();
7 const navigate = useNavigate();
8
9 useEffect(() => {
10 const checkAccess = async () => {
11 const loggedIn = await isLoggedIn();
12 if (!loggedIn || !isSudo()) {
13 navigate({ to: '/login' });
14 }
15 };
16
17 checkAccess();
18 }, [isSudo, isLoggedIn, navigate]);
19
20 if (!isSudo) {
21 return null;
22 }
23
24 return children;
25};
26