mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 19:41:09 +02:00
fix(manacore-web): await getAuthUrl() and use runtime config in user-settings
Critical fixes for runtime configuration: - auth.svelte.ts: Added missing await on getAuthUrl() in validateReferralCode() - user-settings.svelte.ts: Replaced window injection with runtime config loading This fixes ERR_CONNECTION_REFUSED on staging by ensuring auth URL is properly loaded from config.json before making API calls.
This commit is contained in:
parent
9b55f10c28
commit
b2a8ffa6d9
2 changed files with 13 additions and 13 deletions
|
|
@ -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' };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue