feature: a minimal implementation of staff management is done.
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
'use client';
|
||||
|
||||
import { memo, useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { useAuth } from '@/lib/hooks/useAuth';
|
||||
import Sidebar from '@/components/ui/Sidebar';
|
||||
import { ThemeToggle } from '@/components/ui/ThemeToggle';
|
||||
import { DashboardAccountMenu } from '@/components/ui/DashboardAccountMenu';
|
||||
import {
|
||||
firstAccessibleDashboardPath,
|
||||
getRequiredReadPermissionForPath,
|
||||
hasPermission,
|
||||
} from '@/access';
|
||||
|
||||
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
|
||||
const { user, currentOrganization, isAuthReady } = useAuth();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
// ✅ AUTH GUARD (runs once per navigation group)
|
||||
useEffect(() => {
|
||||
@@ -24,7 +30,12 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
|
||||
router.replace('/select-organization');
|
||||
return;
|
||||
}
|
||||
}, [isAuthReady, user, currentOrganization, router]);
|
||||
|
||||
const required = getRequiredReadPermissionForPath(pathname);
|
||||
if (required && !hasPermission(currentOrganization, required)) {
|
||||
router.replace(firstAccessibleDashboardPath(currentOrganization));
|
||||
}
|
||||
}, [isAuthReady, user, currentOrganization, router, pathname]);
|
||||
|
||||
// ✅ LOADING ONLY FOR INITIAL LOAD
|
||||
if (!isAuthReady) {
|
||||
|
||||
Reference in New Issue
Block a user