diff --git a/apps/manacore/apps/web/src/lib/stores/auth.svelte.ts b/apps/manacore/apps/web/src/lib/stores/auth.svelte.ts index a18e5351b..36dd5edfc 100644 --- a/apps/manacore/apps/web/src/lib/stores/auth.svelte.ts +++ b/apps/manacore/apps/web/src/lib/stores/auth.svelte.ts @@ -154,7 +154,8 @@ export const authStore = { */ async validateReferralCode(code: string) { try { - const response = await fetch(`${getAuthUrl()}/api/v1/referrals/validate/${code}`); + const authUrl = await getAuthUrl(); + const response = await fetch(`${authUrl}/api/v1/referrals/validate/${code}`); if (!response.ok) { return { valid: false, error: 'Invalid code' }; } diff --git a/apps/manacore/apps/web/src/lib/stores/user-settings.svelte.ts b/apps/manacore/apps/web/src/lib/stores/user-settings.svelte.ts index 7ce7f1600..4bd6f7ee1 100644 --- a/apps/manacore/apps/web/src/lib/stores/user-settings.svelte.ts +++ b/apps/manacore/apps/web/src/lib/stores/user-settings.svelte.ts @@ -7,22 +7,21 @@ * - localStorage caching for offline support */ -import { browser } from '$app/environment'; import { createUserSettingsStore } from '@manacore/shared-theme'; import { authStore } from './auth.svelte'; +import { getAuthUrl } from '$lib/config/runtime'; -// Get auth URL dynamically at runtime -function getAuthUrl(): string { - if (browser && typeof window !== 'undefined') { - const injectedUrl = (window as unknown as { __PUBLIC_MANA_CORE_AUTH_URL__?: string }) - .__PUBLIC_MANA_CORE_AUTH_URL__; - return injectedUrl || 'http://localhost:3001'; - } - return 'http://localhost:3001'; -} - +// Create store with async initialization export const userSettings = createUserSettingsStore({ appId: 'manacore', - authUrl: getAuthUrl(), + authUrl: 'http://localhost:3001', // Will be updated after config loads getAccessToken: () => authStore.getAccessToken(), }); + +// Update auth URL after runtime config loads +getAuthUrl().then((url) => { + // Update the store's auth URL after config loads + if (userSettings.settings) { + (userSettings.settings as { authUrl: string }).authUrl = url; + } +});