/
Garuda
/
Spas
Обзор
Документация
Войти
/
Garuda
/
Spas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/components/AuthGuard.tsx
24 строки
495 B
Torward
Initial commit
11 фев 2025, 04:42
11 фев 2025, 04:42
6057923
Код
Авторство
О чём код?
import { useAuth } from "@/lib/auth"; import { Navigate } from "react-router-dom"; interface AuthGuardProps { children: React.ReactNode; requireDispatcher?: boolean; } export const AuthGuard = ({ children, requireDispatcher = false, }: AuthGuardProps) => { const { user, isDispatcher } = useAuth(); if (!user) { return <Navigate to="/login" replace />; } if (requireDispatcher && !isDispatcher) { return <Navigate to="/" replace />; } return <>{children}</>; };