admin/components/auth/PendingUserGuard.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

33 lines
846 B
TypeScript

'use client'
import { useRouter } from 'next/navigation'
import { useEffect } from 'react'
import useAuth from '@/hooks/useAuth'
/**
* Handles accounts that are still `pending` profile completion.
* - Consumer users keep the current page visible; AuthGate modal collects profile.
* - Admins are redirected to `/auth?step=profile` and the shell is hidden meanwhile.
*/
const PendingUserGuard = ({ children }: { children: React.ReactNode }) => {
const { user } = useAuth()
const router = useRouter()
const isPending = user?.status === 'pending'
const isAdmin = user?.role === 'admin'
useEffect(() => {
if (isPending && isAdmin) {
router.replace('/auth?step=profile')
}
}, [isAdmin, isPending, router])
if (isPending && isAdmin) {
return null
}
return <>{children}</>
}
export default PendingUserGuard