pos-dashboard-v2/src/hocs/GuestOnlyRoute.tsx
2025-08-14 00:29:19 +07:00

35 lines
774 B
TypeScript

'use client'
// Next Imports
// Type Imports
import type { ChildrenType } from '@core/types'
import { useRouter } from 'next/navigation'
import { useEffect } from 'react'
import { useAuth } from '../contexts/authContext'
import Loading from '../components/layout/shared/Loading'
// Config Imports
// Util Imports
const GuestOnlyRoute = ({ children }: ChildrenType) => {
const router = useRouter()
const { isAuthenticated, currentUser } = useAuth()
useEffect(() => {
if (!isAuthenticated) return
if (currentUser?.role === 'admin') {
router.push('/dashboards/overview')
} else {
router.push('/sa/organizations/list')
}
}, [isAuthenticated])
return <>{isAuthenticated ? <Loading /> : children}</>
}
export default GuestOnlyRoute