first commit
This commit is contained in:
18
frontend/src/auth/RequireAdmin.tsx
Normal file
18
frontend/src/auth/RequireAdmin.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
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}</>
|
||||
}
|
||||
Reference in New Issue
Block a user