Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix: Fix Neon Auth Origin header rejection for Electron desktop app and API proxy

Gabriel Steinc33cd1b89f52
diff --git a/README.md b/README.md
index 87e28ccc8..52dcb72fe 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
# OpenWhispr
+[![Downloads](https://img.shields.io/github/downloads/OpenWhispr/openwhispr/total?style=flat&color=blue)](https://github.com/OpenWhispr/openwhispr/releases)
+
An open source desktop dictation application that converts speech to text using OpenAI Whisper. Features both local and cloud processing options for maximum flexibility and privacy.
## Star History
diff --git a/main.js b/main.js
index 3c69a167a..30b1b19fd 100644
--- a/main.js
+++ b/main.js
@@ -1,4 +1,4 @@
-const { app, globalShortcut, BrowserWindow, dialog, ipcMain } = require("electron");
+const { app, globalShortcut, BrowserWindow, dialog, ipcMain, session } = require("electron");
const path = require("path");
const http = require("http");
require("dotenv").config({ path: path.join(__dirname, ".env") });
@@ -405,6 +405,26 @@ async function startApp() {
initializeManagers();
startAuthBridgeServer();
+ // Inject Origin header for Neon Auth requests.
+ // Electron loads pages from file:// so the browser sends no Origin header,
+ // which Neon Auth (better-auth) rejects. This is the standard Electron
+ // approach: use webRequest.onBeforeSendHeaders at the Chromium network layer.
+ const neonAuthUrl = process.env.VITE_NEON_AUTH_URL || "";
+ if (neonAuthUrl) {
+ try {
+ const neonOrigin = new URL(neonAuthUrl).origin;
+ session.defaultSession.webRequest.onBeforeSendHeaders(
+ { urls: [`${neonOrigin}/*`] },
+ (details, callback) => {
+ details.requestHeaders["Origin"] = neonOrigin;
+ callback({ requestHeaders: details.requestHeaders });
+ }
+ );
+ } catch (err) {
+ console.error("Failed to set up Neon Auth origin interceptor:", err);
+ }
+ }
+
// Initialize activation mode cache from persisted .env value
windowManager.setActivationModeCache(environmentManager.getActivationMode());
diff --git a/src/lib/neonAuth.ts b/src/lib/neonAuth.ts
index 120da73c6..009247c12 100644
--- a/src/lib/neonAuth.ts
+++ b/src/lib/neonAuth.ts
@@ -2,14 +2,8 @@ import { createAuthClient } from "@neondatabase/auth";
import { BetterAuthReactAdapter } from "@neondatabase/auth/react";
export const NEON_AUTH_URL = import.meta.env.VITE_NEON_AUTH_URL || "";
-// Electron's origin is null/file:// which Neon Auth won't trust.
-// Send the Neon Auth server's own origin so requests pass trustedOrigins validation.
-const neonOrigin = NEON_AUTH_URL ? new URL(NEON_AUTH_URL).origin : "";
export const authClient = NEON_AUTH_URL
- ? createAuthClient(NEON_AUTH_URL, {
- adapter: BetterAuthReactAdapter(),
- fetchOptions: { headers: { Origin: neonOrigin } },
- })
+ ? createAuthClient(NEON_AUTH_URL, { adapter: BetterAuthReactAdapter() })
: null;
export type SocialProvider = "google";