Skip to content

Commit 12cfd6b

Browse files
authored
fix: OAuth login behind nginx — use actual origin for redirect URI (Closes #82) (#86)
Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
1 parent 4a544fe commit 12cfd6b

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ REQUIRE_API_KEY=false
4444
BASE_URL=http://localhost:20128
4545
CLOUD_URL=
4646
# Backward-compatible/public variables:
47+
# NEXT_PUBLIC_BASE_URL is also used as the OAuth redirect_uri origin when running behind a
48+
# reverse proxy (e.g., nginx). Set this to your public-facing URL so OAuth callbacks work.
49+
# Example: NEXT_PUBLIC_BASE_URL=https://omniroute.example.com
4750
NEXT_PUBLIC_BASE_URL=http://localhost:20128
4851
NEXT_PUBLIC_CLOUD_URL=
4952

src/shared/components/OAuthModal.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)