feat: ingredient product

This commit is contained in:
ferdiansyah783
2025-08-12 21:29:24 +07:00
parent c3780af341
commit f3dfad4cb3
36 changed files with 1731 additions and 465 deletions
+7 -3
View File
@@ -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 />}</>
}
+28
View File
@@ -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 />}</>
}