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