@@ -209,13 +209,22 @@ export default function OAuthModal({
209209 }
210210
211211 // Authorization code flow
212- // Always use localhost redirect_uri — this is what providers have registered .
213- // On remote, the browser redirects to localhost (error page), user copies URL and pastes back .
212+ // On localhost: use localhost callback so popup/BroadcastChannel/localStorage can relay code .
213+ // On remote (behind nginx/reverse proxy): use the actual origin so the callback page loads .
214214 // Codex (OpenAI) requires exactly http://localhost:1455/auth/callback — the registered URI.
215- // Other providers (Antigravity/Gemini via Google OAuth) accept any localhost port.
216215 let redirectUri : string ;
217216 if ( provider === "codex" || provider === "openai" ) {
218217 redirectUri = "http://localhost:1455/auth/callback" ;
218+ } else if ( ! isLocalhost ) {
219+ // Behind reverse proxy: use actual origin (e.g., https://omniroute.example.com/callback)
220+ // This ensures the OAuth provider redirects to the proxied URL where the callback page loads.
221+ // Supports PUBLIC_URL env var override, or falls back to window.location.origin.
222+ const publicUrl = process . env . NEXT_PUBLIC_BASE_URL ;
223+ const origin =
224+ publicUrl && publicUrl !== "http://localhost:20128"
225+ ? publicUrl . replace ( / \/ $ / , "" )
226+ : window . location . origin ;
227+ redirectUri = `${ origin } /callback` ;
219228 } else {
220229 const port = window . location . port || ( window . location . protocol === "https:" ? "443" : "80" ) ;
221230 redirectUri = `http://localhost:${ port } /callback` ;
0 commit comments