From 5f7bce9b02d8a587a262da305fefc9756dbe1c49 Mon Sep 17 00:00:00 2001 From: Corentin Date: Fri, 8 May 2026 12:34:38 +0200 Subject: [PATCH] =?UTF-8?q?fix(client):=20read=20VITE=5FBRIDGE=5FTOKEN=20v?= =?UTF-8?q?ia=20process.env=20(define=20block=20target)=20=E2=80=94=20Patc?= =?UTF-8?q?h=20023?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous fix (Patch 021) read import.meta.env.VITE_BRIDGE_TOKEN, but Vite only auto-exposes VITE_* in import.meta.env when the .env lives in apps/client/. Our .env is at the monorepo root and is loaded via loadEnv() in vite.config.ts, then injected through the define block under the 'process.env' key. So the runtime variable lives at process.env.VITE_BRIDGE_TOKEN, not import.meta.env.VITE_BRIDGE_TOKEN. Without this, the bridge proxy received no Bearer header and returned 401 Unauthorized for every /database slash command request — exactly what Corentin reported. Patch 023. --- .../acadenice/database-view/services/bridge-client.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/client/src/features/acadenice/database-view/services/bridge-client.ts b/apps/client/src/features/acadenice/database-view/services/bridge-client.ts index 3d2d4fc5..d04bca74 100644 --- a/apps/client/src/features/acadenice/database-view/services/bridge-client.ts +++ b/apps/client/src/features/acadenice/database-view/services/bridge-client.ts @@ -57,10 +57,15 @@ export function createBridgeClient(bridgeUrl: string): AxiosInstance { }); instance.interceptors.request.use((config) => { - // Priority: cookie token (prod) > VITE_BRIDGE_TOKEN env (dev fallback) + // Priority: cookie token (prod) > VITE_BRIDGE_TOKEN env (dev fallback). + // Vite's define block in vite.config.ts injects VITE_BRIDGE_TOKEN into + // process.env at build/dev time (not into import.meta.env, since the .env + // is loaded from the monorepo root, not from apps/client/). const cookieToken = readTokenFromCookie(); - const metaEnv = (import.meta as unknown as { env?: { VITE_BRIDGE_TOKEN?: string } }).env; - const envToken = metaEnv?.VITE_BRIDGE_TOKEN; + const envToken = + typeof process !== "undefined" + ? (process.env as unknown as { VITE_BRIDGE_TOKEN?: string })?.VITE_BRIDGE_TOKEN + : undefined; const token = cookieToken || envToken; if (token) { config.headers["Authorization"] = `Bearer ${token}`;