feat: ingredient product
This commit is contained in:
@@ -12,13 +12,17 @@ import Loading from '../components/layout/shared/Loading'
|
||||
import { getLocalizedUrl } from '../utils/i18n'
|
||||
|
||||
export default function AuthGuard({ children, locale }: ChildrenType & { locale: Locale }) {
|
||||
const { isAuthenticated } = useAuth()
|
||||
const { isAuthenticated, currentUser } = useAuth()
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
redirect(getLocalizedUrl('/login', locale))
|
||||
}
|
||||
}, [isAuthenticated])
|
||||
|
||||
return <>{isAuthenticated ? children : <Loading />}</>
|
||||
if (currentUser?.role !== 'admin') {
|
||||
redirect(getLocalizedUrl('/not-found', locale))
|
||||
}
|
||||
}, [isAuthenticated, currentUser])
|
||||
|
||||
return <>{isAuthenticated && currentUser?.role === 'admin' ? children : <Loading />}</>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
'use client'
|
||||
|
||||
// Type Imports
|
||||
import type { Locale } from '@configs/i18n'
|
||||
import type { ChildrenType } from '@core/types'
|
||||
import { useEffect } from 'react'
|
||||
import { useAuth } from '../contexts/authContext'
|
||||
|
||||
// Component Imports
|
||||
import { redirect } from 'next/navigation'
|
||||
import Loading from '../components/layout/shared/Loading'
|
||||
import { getLocalizedUrl } from '../utils/i18n'
|
||||
|
||||
export default function RolesGuard({ children, locale }: ChildrenType & { locale: Locale }) {
|
||||
const { isAuthenticated, currentUser } = useAuth()
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
redirect(getLocalizedUrl('/login', locale))
|
||||
}
|
||||
|
||||
if (currentUser?.role !== 'superadmin') {
|
||||
redirect(getLocalizedUrl('/not-found', locale))
|
||||
}
|
||||
}, [isAuthenticated, currentUser])
|
||||
|
||||
return <>{isAuthenticated && currentUser?.role === 'superadmin' ? children : <Loading />}</>
|
||||
}
|
||||
Reference in New Issue
Block a user