Files
gridpilot.gg/apps/website/app/auth/layout.tsx
2026-01-14 23:46:04 +01:00

32 lines
941 B
TypeScript

import { headers } from 'next/headers';
import { redirect } from 'next/navigation';
import { createRouteGuard } from '@/lib/auth/createRouteGuard';
import { AuthContainer } from '@/ui/AuthContainer';
interface AuthLayoutProps {
children: React.ReactNode;
}
/**
* Auth Layout
*
* Provides authentication route protection for all auth routes.
* Uses RouteGuard to enforce access control server-side.
*
* Behavior:
* - Unauthenticated users can access auth pages (login, signup, etc.)
* - Authenticated users are redirected away from auth pages
*/
export default async function AuthLayout({ children }: AuthLayoutProps) {
const headerStore = await headers();
const pathname = headerStore.get('x-pathname') || '/';
const guard = createRouteGuard();
const result = await guard.enforce({ pathname });
if (result.type === 'redirect') {
redirect(result.to);
}
return <AuthContainer>{children}</AuthContainer>;
}