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}`;