From be37808966d9b02aca17b36bf22c68a9748a08cc Mon Sep 17 00:00:00 2001 From: Wuesteon Date: Fri, 5 Dec 2025 02:49:32 +0100 Subject: [PATCH] fix(chat-web): use runtime env vars instead of static imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed PUBLIC_MANA_CORE_AUTH_URL from $env/static/public to runtime environment variables so the Docker build doesn't fail. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../apps/web/src/lib/services/feedback.ts | 4 ++-- .../apps/web/src/lib/stores/auth.svelte.ts | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/chat/apps/web/src/lib/services/feedback.ts b/apps/chat/apps/web/src/lib/services/feedback.ts index bbef27247..a68733fa4 100644 --- a/apps/chat/apps/web/src/lib/services/feedback.ts +++ b/apps/chat/apps/web/src/lib/services/feedback.ts @@ -4,9 +4,9 @@ import { createFeedbackService } from '@manacore/shared-feedback-service'; import { authStore } from '$lib/stores/auth.svelte'; -import { PUBLIC_MANA_CORE_AUTH_URL } from '$env/static/public'; -const MANA_AUTH_URL = PUBLIC_MANA_CORE_AUTH_URL || 'http://localhost:3001'; +// Use environment variable at runtime +const MANA_AUTH_URL = process.env.PUBLIC_MANA_CORE_AUTH_URL || 'http://localhost:3001'; export const feedbackService = createFeedbackService({ apiUrl: MANA_AUTH_URL, diff --git a/apps/chat/apps/web/src/lib/stores/auth.svelte.ts b/apps/chat/apps/web/src/lib/stores/auth.svelte.ts index 413ce5ef0..93a166a78 100644 --- a/apps/chat/apps/web/src/lib/stores/auth.svelte.ts +++ b/apps/chat/apps/web/src/lib/stores/auth.svelte.ts @@ -6,10 +6,21 @@ import { browser } from '$app/environment'; import { initializeWebAuth } from '@manacore/shared-auth'; import type { UserData } from '@manacore/shared-auth'; -import { PUBLIC_MANA_CORE_AUTH_URL } from '$env/static/public'; -// Initialize Mana Core Auth only on the client side -const MANA_AUTH_URL = PUBLIC_MANA_CORE_AUTH_URL || 'http://localhost:3001'; +// Get auth URL dynamically at runtime - fallback for SSR and client +function getAuthUrl(): string { + if (browser && typeof window !== 'undefined') { + // Client-side: check for injected env or use default + return ( + (window as unknown as { __PUBLIC_MANA_CORE_AUTH_URL__?: string }) + .__PUBLIC_MANA_CORE_AUTH_URL__ || + import.meta.env.PUBLIC_MANA_CORE_AUTH_URL || + 'http://localhost:3001' + ); + } + // Server-side: use process.env or default + return process.env.PUBLIC_MANA_CORE_AUTH_URL || 'http://localhost:3001'; +} // Lazy initialization to avoid SSR issues with localStorage let _authService: ReturnType['authService'] | null = null; @@ -18,7 +29,7 @@ let _tokenManager: ReturnType['tokenManager'] | null = function getAuthService() { if (!browser) return null; if (!_authService) { - const auth = initializeWebAuth({ baseUrl: MANA_AUTH_URL }); + const auth = initializeWebAuth({ baseUrl: getAuthUrl() }); _authService = auth.authService; _tokenManager = auth.tokenManager; }