mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 01:35:39 -04:00
Replace client-side session checks (useSession + router.replace) with a two-layer server-side approach: Next.js middleware performs a fast cookie presence check for all protected routes, and the (pages) layout does a full server-side session validation before rendering. Move login/register into a dedicated (auth) route group with its own minimal layout so they sit outside the authenticated shell. Lift the Toaster to the root layout so it remains available across all route groups.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { headers } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
import { CommandPalette } from "@/components/command-palette";
|
|
import { KeyboardHelpDialog } from "@/components/keyboard-help-dialog";
|
|
import { KeyboardProvider } from "@/components/keyboard-provider";
|
|
import { MobileTabBar } from "@/components/mobile-tab-bar";
|
|
import { NavBar } from "@/components/nav-bar";
|
|
import { auth } from "@/lib/auth/server";
|
|
|
|
export default async function PagesLayout({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
const session = await auth.api.getSession({ headers: await headers() });
|
|
if (!session) redirect("/login");
|
|
|
|
return (
|
|
<KeyboardProvider>
|
|
<div className="min-h-screen overflow-x-hidden pb-14 sm:pb-0">
|
|
<NavBar />
|
|
{/* Ambient glow */}
|
|
<div className="pointer-events-none fixed left-1/2 top-1/4 -translate-x-1/2 -translate-y-1/2 h-[600px] w-[800px] rounded-full bg-primary/3 blur-[200px]" />
|
|
<main className="relative mx-auto max-w-6xl px-4 py-6 sm:px-6">
|
|
{children}
|
|
</main>
|
|
</div>
|
|
<MobileTabBar />
|
|
<CommandPalette />
|
|
<KeyboardHelpDialog />
|
|
</KeyboardProvider>
|
|
);
|
|
}
|