@mounaji_npm/layout-guards
v0.4.2
Published
Route and access guard hooks for production Mounaji shell layouts
Maintainers
Readme
@mounaji_npm/layout-guards
Route/layout guard helpers for authentication, whitelist access, and shell visibility.
Install
npm install @mounaji_npm/layout-guardsQuick Start
import { useLayoutGuards } from '@mounaji_npm/layout-guards';
import { usePathname, useRouter } from 'next/navigation';
export function ProtectedLayout({ loading, user, isWhitelisted, children }) {
const pathname = usePathname();
const router = useRouter();
const { allowRender, showShell, showLoading } = useLayoutGuards({
pathname,
router,
loading,
user,
isWhitelisted,
});
if (!allowRender) return null;
if (showLoading) return <div>Loading...</div>;
return showShell ? <AppShell>{children}</AppShell> : children;
}Exports
useLayoutGuards(options)— computes render and redirect behavior for protected routes.isBypassPath(pathname, bypassPaths?)— utility to test bypass paths.DEFAULT_BYPASS_PATHS— built-in bypass routes (login, terms, privacy, access-denied, etc.).
useLayoutGuards options
pathname— current route path.router— object withreplace(path).loading— auth/capabilities loading state.user— current user object.isWhitelisted—true,false, ornullwhile resolving.bypassPaths— optional route prefixes exempt from redirects.standalonePrefixes— optional route prefixes that should render without shell.
