first commit
This commit is contained in:
23
apps/frontend/app/admin/layout.tsx
Normal file
23
apps/frontend/app/admin/layout.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useAuth } from '@/components/id/auth-provider';
|
||||
|
||||
export default function AdminLayout({ children }: { children: React.ReactNode }) {
|
||||
const router = useRouter();
|
||||
const { user, isLoading, isPinLocked, hasStoredSession } = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading) return;
|
||||
if (!user && !isPinLocked && !hasStoredSession) {
|
||||
router.replace('/auth/login');
|
||||
return;
|
||||
}
|
||||
if (user && !user.canAccessAdmin) {
|
||||
router.replace('/');
|
||||
}
|
||||
}, [hasStoredSession, isLoading, isPinLocked, router, user]);
|
||||
|
||||
return children;
|
||||
}
|
||||
Reference in New Issue
Block a user