From af1f5d6fc621409423f76f21291876fa1faff181 Mon Sep 17 00:00:00 2001 From: Michele Date: Sat, 31 Jan 2026 06:16:07 +0100 Subject: [PATCH] feat(01-03): add auth callback route for code exchange - Handle OAuth and email verification callback - Exchange code for session using Supabase SSR - Redirect to next param or /dashboard on success - Redirect to /login with error on failure Co-Authored-By: Claude Opus 4.5 --- src/app/auth/callback/route.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/app/auth/callback/route.ts diff --git a/src/app/auth/callback/route.ts b/src/app/auth/callback/route.ts new file mode 100644 index 0000000..7b76f5e --- /dev/null +++ b/src/app/auth/callback/route.ts @@ -0,0 +1,20 @@ +import { createClient } from '@/lib/supabase/server' +import { NextResponse } from 'next/server' + +export async function GET(request: Request) { + const { searchParams, origin } = new URL(request.url) + const code = searchParams.get('code') + const next = searchParams.get('next') ?? '/dashboard' + + if (code) { + const supabase = await createClient() + const { error } = await supabase.auth.exchangeCodeForSession(code) + + if (!error) { + return NextResponse.redirect(`${origin}${next}`) + } + } + + // Return the user to an error page with instructions + return NextResponse.redirect(`${origin}/login?error=auth_callback_error`) +}