fix(spaces): keep process.env out of the browser branch in authBaseUrl

Opening the Space-Switcher threw "process is not defined" because the
missing-injection fallback inside the browser branch returned early
only when the injected URL was truthy, then fell through to a
`process.env.PUBLIC_MANA_AUTH_URL` read. `process` doesn't exist in
the browser, so empty injection = ReferenceError.

Fix: the browser branch now always returns (injected or localhost:3001
fallback) without touching `process`. The env-var read stays inside
the SSR path and is further guarded by `typeof process !== 'undefined'`
so a future change can't regress.

0 errors across 7203 files.

Plan: docs/plans/spaces-foundation.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-21 13:55:32 +02:00
parent f17383f9f2
commit c9141e3b35

View file

@ -15,12 +15,19 @@
import { browser } from '$app/environment';
export function authBaseUrl(): string {
// Browser: read the runtime-injected URL, fall back to localhost dev.
// `process` is not defined in browsers, so the env-var branch below
// MUST stay inside the server-side path to avoid a ReferenceError.
if (browser && typeof window !== 'undefined') {
const injected = (window as unknown as { __PUBLIC_MANA_AUTH_URL__?: string })
.__PUBLIC_MANA_AUTH_URL__;
if (injected) return injected.replace(/\/$/, '');
return (injected || 'http://localhost:3001').replace(/\/$/, '');
}
return (process.env.PUBLIC_MANA_AUTH_URL || 'http://localhost:3001').replace(/\/$/, '');
// SSR: Node has `process.env`.
const fromEnv =
(typeof process !== 'undefined' && process.env?.PUBLIC_MANA_AUTH_URL) ||
'http://localhost:3001';
return fromEnv.replace(/\/$/, '');
}
/**