export const dynamic = 'force-dynamic';
import { createClient } from '@/lib/supabase/server';
import { NextResponse } from 'next/server';

export async function GET(request: Request) {
    const requestUrl = new URL(request.url);
    const code = requestUrl.searchParams.get('code');

    if (code) {
        const supabase = await createClient();
        await supabase.auth.exchangeCodeForSession(code);
    }

    // Prefer SITE_URL from env, fall back to request origin (local dev)
    const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || requestUrl.origin;

    // URL to redirect to after sign in process completes
    return NextResponse.redirect(`${baseUrl}/`);
}
