import { NextResponse, type NextRequest } from "next/server"; import { SESSION_COOKIE } from "@/lib/auth/session"; const PROTECTED_PREFIXES = ["/practice", "/camera", "/profile", "/onboarding"]; export function proxy(req: NextRequest) { const { pathname } = req.nextUrl; if (!PROTECTED_PREFIXES.some((p) => pathname === p || pathname.startsWith(p + "/"))) { return NextResponse.next(); } const hasSession = Boolean(req.cookies.get(SESSION_COOKIE)?.value); if (!hasSession) { const url = req.nextUrl.clone(); url.pathname = "/"; url.searchParams.set("next", pathname); return NextResponse.redirect(url); } return NextResponse.next(); } export const config = { matcher: ["/practice/:path*", "/camera/:path*", "/profile/:path*", "/onboarding/:path*"], };