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 <noreply@anthropic.com>
This commit is contained in:
Michele
2026-01-31 06:16:07 +01:00
parent fc5e799212
commit af1f5d6fc6

View File

@@ -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`)
}