import { NextResponse } from "next/server"; import { sessionUser } from "@/lib/session-server"; export const dynamic = "force-dynamic"; // BioLock sign-in returns here after the session is created. export async function GET(request: Request) { const url = new URL(request.url); const nextParam = url.searchParams.get("next") ?? "/account"; let next = "/account"; if (nextParam.startsWith("/")) { const target = URL.parse(nextParam, url.origin); if (target?.origin === url.origin && !target.pathname.startsWith("//")) { next = target.href.slice(url.origin.length); } } const user = await sessionUser(request).catch(() => null); if (!user) { return NextResponse.redirect(new URL("/login?error=auth_error", url.origin)); } return NextResponse.redirect(new URL(next, url.origin)); }