import { NextResponse } from 'next/server' import { createClient } from '@/utils/supabase/server' export async function GET(request: Request) { const { searchParams, origin } = new URL(request.url) const code = searchParams.get('code') const next = searchParams.get('next') ?? '/app' const error = searchParams.get('error') const error_description = searchParams.get('error_description') if (code) { const supabase = await createClient() const { error: supabaseError } = await supabase.auth.exchangeCodeForSession(code) if (!supabaseError) { await supabase.rpc('reactivate_profile') return NextResponse.redirect(`${origin}${next}`) } } // If there's an error from Supabase or from the URL, forward it if (error) { return NextResponse.redirect(`${origin}/login?error=${globalThis.encodeURIComponent(error_description || error)}`) } // return the user to an error page with instructions return NextResponse.redirect(`${origin}/login?code_error=true`) }