Branchwell

Become a Pro / website · becomeapro.ai / src / app / auth / callback / route.ts

Raw 822 B on 59dac1cc932d622dfc4d6c274a9ed8e9abcc5e5e
1import { NextResponse } from "next/server";
2import { sessionUser } from "@/lib/session-server";
3
4export const dynamic = "force-dynamic";
5
6// BioLock sign-in returns here after the session is created.
7export async function GET(request: Request) {
8 const url = new URL(request.url);
9 const nextParam = url.searchParams.get("next") ?? "/account";
10 let next = "/account";
11 if (nextParam.startsWith("/")) {
12 const target = URL.parse(nextParam, url.origin);
13 if (target?.origin === url.origin && !target.pathname.startsWith("//")) {
14 next = target.href.slice(url.origin.length);
15 }
16 }
17
18 const user = await sessionUser(request).catch(() => null);
19 if (!user) {
20 return NextResponse.redirect(new URL("/login?error=auth_error", url.origin));
21 }
22 return NextResponse.redirect(new URL(next, url.origin));
23}