admin/components/auth/AdminRoleGuard.tsx
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

27 lines
568 B
TypeScript

'use client'
import { useRouter } from 'next/navigation'
import { useEffect } from 'react'
import { CONSUMER_ROUTES } from '@/constants/routes'
import useAuth from '@/hooks/useAuth'
const AdminRoleGuard = ({ children }: { children: React.ReactNode }) => {
const { user } = useAuth()
const router = useRouter()
useEffect(() => {
if (user && user.role !== 'admin') {
router.replace(CONSUMER_ROUTES.HOME)
}
}, [router, user])
if (user && user.role !== 'admin') {
return null
}
return <>{children}</>
}
export default AdminRoleGuard