Become a Pro / website · becomeapro.ai / src / app / auth / callback / route.ts
| 1 | import { NextResponse } from "next/server"; |
| 2 | import { sessionUser } from "@/lib/session-server"; |
| 3 | |
| 4 | export const dynamic = "force-dynamic"; |
| 5 | |
| 6 | // BioLock sign-in returns here after the session is created. |
| 7 | export 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 | } |