From 8e40e51ed3855ca267f60f2f2b5b6e0ba7dc418b Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Thu, 16 Apr 2026 12:51:39 -0700 Subject: [PATCH] fix: prefix /api/session and /api/preferences with VITE_API_BASE Both stores hardcoded /api/* paths without reading VITE_API_BASE, causing /api/session to hit the menagerie root (no /snipe prefix) and receive a 302 redirect to circuitforge.tech/login instead of a session response. Every other store already read VITE_API_BASE correctly. --- web/src/stores/preferences.ts | 6 ++++-- web/src/stores/session.ts | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/web/src/stores/preferences.ts b/web/src/stores/preferences.ts index bbb5de1..3402738 100644 --- a/web/src/stores/preferences.ts +++ b/web/src/stores/preferences.ts @@ -11,6 +11,8 @@ export interface UserPreferences { } } +const apiBase = (import.meta.env.VITE_API_BASE as string) ?? '' + export const usePreferencesStore = defineStore('preferences', () => { const session = useSessionStore() const prefs = ref({}) @@ -25,7 +27,7 @@ export const usePreferencesStore = defineStore('preferences', () => { loading.value = true error.value = null try { - const res = await fetch('/api/preferences') + const res = await fetch(`${apiBase}/api/preferences`) if (res.ok) { prefs.value = await res.json() } @@ -40,7 +42,7 @@ export const usePreferencesStore = defineStore('preferences', () => { if (!session.isLoggedIn) return error.value = null try { - const res = await fetch('/api/preferences', { + const res = await fetch(`${apiBase}/api/preferences`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ path, value }), diff --git a/web/src/stores/session.ts b/web/src/stores/session.ts index 570d0e2..4eddabc 100644 --- a/web/src/stores/session.ts +++ b/web/src/stores/session.ts @@ -42,8 +42,9 @@ export const useSessionStore = defineStore('session', () => { const isLoggedIn = computed(() => isCloud.value && userId.value !== 'anonymous' && !isGuest.value) async function bootstrap() { + const apiBase = (import.meta.env.VITE_API_BASE as string) ?? '' try { - const res = await fetch('/api/session') + const res = await fetch(`${apiBase}/api/session`) if (!res.ok) return // local-mode with no session endpoint — keep defaults const data = await res.json() userId.value = data.user_id