import { NextResponse } from 'next/server' import { getGoogleAuthUrl, googleEnabled } from '@/lib/google-oauth' function safeNext(raw: string | null): string { return raw && raw.startsWith('/') && !raw.startsWith('//') ? raw : '/' } const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'https://lotoloki.top' export async function GET(req: Request) { const url = new URL(req.url) if (!googleEnabled) { return NextResponse.redirect(`${SITE_URL}/connexion?error=google_not_configured`) } const next = safeNext(url.searchParams.get('next')) const state = `${crypto.randomUUID()}.${encodeURIComponent(next)}` const res = NextResponse.redirect(getGoogleAuthUrl(state)) res.cookies.set('g_state', state, { httpOnly: true, sameSite: 'lax', secure: process.env.NODE_ENV === 'production', maxAge: 600, path: '/', }) return res }