From fca54d4215cd594e68c3e8e22c15485f2558df7e Mon Sep 17 00:00:00 2001 From: rikhall1515 <30295873+rikhall1515@users.noreply.github.com> Date: Thu, 18 Apr 2024 21:17:29 +0200 Subject: [PATCH] feat(db): add auth callback with redirect --- app/auth/callback/route.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/auth/callback/route.ts diff --git a/app/auth/callback/route.ts b/app/auth/callback/route.ts new file mode 100644 index 0000000..fbe3bc2 --- /dev/null +++ b/app/auth/callback/route.ts @@ -0,0 +1,20 @@ +import { NextResponse } from "next/server"; + +import { createClient } from "@/db/server"; + +export async function GET(request: Request) { + // The `/auth/callback` route is required for the server-side auth flow implemented + // by the SSR package. It exchanges an auth code for the user's session. + // https://supabase.com/docs/guides/auth/server-side/nextjs + const requestUrl = new URL(request.url); + const code = requestUrl.searchParams.get("code"); + const origin = requestUrl.origin; + + if (code) { + const supabase = createClient(); + await supabase.auth.exchangeCodeForSession(code); + } + + // URL to redirect to after sign up process completes + return NextResponse.redirect(`${origin}/protected`); +}