Files
vidconf/frontend/src/auth/RequireAdmin.tsx
Max Ronzhin 8757bec8ac
Some checks failed
CI / backend (push) Has been cancelled
CI / frontend (push) Has been cancelled
first commit
2026-07-23 02:38:05 +03:00

19 lines
670 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { ReactNode } from 'react'
import { Navigate } from 'react-router-dom'
import { useAuth } from '@/auth/useAuth'
/**
* Route-guard админки: доступ только у пользователей с ролью
* `admin`. Оборачивается ВНУТРИ `RequireAuth` (сессия уже гарантированно
* восстановлена и `user` заполнен) — без сессии сюда не попасть.
*/
export function RequireAdmin({ children }: { children: ReactNode }) {
const { user } = useAuth()
if (user?.role !== 'admin') {
return <Navigate to="/lobby" replace />
}
return <>{children}</>
}