From 9b33a2683ba9802fd9145895f787af4c6928ee63 Mon Sep 17 00:00:00 2001 From: Corentin Date: Fri, 8 May 2026 12:44:18 +0200 Subject: [PATCH] =?UTF-8?q?fix(client):=20switch=20bridge=20token=20to=20i?= =?UTF-8?q?mport.meta.env=20(Vite=20auto-expose)=20=E2=80=94=20Patch=20025?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch 023 attempted to read process.env.VITE_BRIDGE_TOKEN, but the vite.config.ts define block uses { 'process.env': {...} } which only substitutes the literal expression 'process.env' standalone, not when followed by a member access like 'process.env.X'. So the runtime call evaluated to undefined and the bridge interceptor never sent a Bearer header — every /database call got 401. Switch to Vite's standard pattern: VITE_BRIDGE_TOKEN lives in apps/client/.env.local (gitignored, must be created locally) and is auto-exposed via import.meta.env. Verified: the dev server substitutes it inline at transform time as 'brg_smoketest_admin'. Patch 025. --- .../database-view/services/bridge-client.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 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 d04bca74..a4aae2a3 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 @@ -56,16 +56,17 @@ export function createBridgeClient(bridgeUrl: string): AxiosInstance { timeout: 15_000, }); + // Vite auto-exposes VITE_* vars from apps/client/.env(.local) via + // import.meta.env. The monorepo-root .env is not picked up automatically + // for client-side consumption, so the dev token lives in apps/client/.env.local + // (gitignored). + const envToken: string | undefined = ( + import.meta as unknown as { env?: { VITE_BRIDGE_TOKEN?: string } } + ).env?.VITE_BRIDGE_TOKEN; + instance.interceptors.request.use((config) => { - // 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/). + // Priority: cookie token (prod) > VITE_BRIDGE_TOKEN env (dev fallback) const cookieToken = readTokenFromCookie(); - 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}`;