Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
27 lines
568 B
TypeScript
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
|