fix: guest route
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user