// Google OAuth callback proxy on the docdoe.in domain. // // WHY: Google's consent screen shows the host of the OAuth redirect_uri. When // that points straight at the backend (asnannp-docdoeai.hf.space) the screen // reads "to continue to asnannp-docdoeai.hf.space". Registering THIS route as // the redirect_uri makes Google show "to continue to www.docdoe.in" instead. // // FLOW: // Google -> https://www.docdoe.in/api/auth/google/callback?code=..&state=.. // -> 302 to /auth/google/callback?code=..&state=.. // -> backend exchanges the code (redirect_uri must equal THIS url) // -> backend 302s to /auth/google/callback#access_token=.. (frontend page) // // REQUIRED config to activate (do these together): // * HF Space env: GOOGLE_OAUTH_REDIRECT_URI=https://www.docdoe.in/api/auth/google/callback // * Google Console -> Clients -> Authorized redirect URIs: add the same URL import { NextResponse } from "next/server"; const BACKEND_BASE = (process.env.NEXT_PUBLIC_API_BASE_URL || "https://asnannp-docdoeai.hf.space").replace(/\/$/, ""); export const dynamic = "force-dynamic"; export function GET(request: Request) { const incoming = new URL(request.url); const target = new URL(`${BACKEND_BASE}/auth/google/callback`); // Forward exactly the params Google sent (code, state, error, scope, ...). incoming.searchParams.forEach((value, key) => { target.searchParams.set(key, value); }); return NextResponse.redirect(target.toString(), 302); }