fix: guest route

This commit is contained in:
ferdiansyah783
2025-08-14 00:29:19 +07:00
parent c01db516b1
commit 1cd8adc1e2
9 changed files with 32 additions and 34 deletions
+19 -8
View File
@@ -1,23 +1,34 @@
'use client'
// Next Imports
// Type Imports
import type { Locale } from '@configs/i18n'
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 = async ({ children, lang }: ChildrenType & { lang: Locale }) => {
// const session = await getServerSession()
const GuestOnlyRoute = ({ children }: ChildrenType) => {
const router = useRouter()
// if (session) {
// redirect(getLocalizedUrl(themeConfig.homePageUrl, lang))
// }
const { isAuthenticated, currentUser } = useAuth()
console.log(lang)
useEffect(() => {
if (!isAuthenticated) return
return <>{children}</>
if (currentUser?.role === 'admin') {
router.push('/dashboards/overview')
} else {
router.push('/sa/organizations/list')
}
}, [isAuthenticated])
return <>{isAuthenticated ? <Loading /> : children}</>
}
export default GuestOnlyRoute