diff --git a/admin/src/api/client.ts b/admin/src/api/client.ts index dd5b0f8f..5914a8e9 100644 --- a/admin/src/api/client.ts +++ b/admin/src/api/client.ts @@ -23,6 +23,12 @@ export function isDemoActive(): boolean { return demoActive; } +// Deactivate demo mode (on logout) — interceptor will pass through to real backend +export function deactivateDemoMode(): void { + demoActive = false; + demoReady = null; +} + // Auto-activate demo if page reloads with a demo token in localStorage function checkDemoToken(): boolean { const token = localStorage.getItem("admin_token"); diff --git a/admin/src/api/demo/index.ts b/admin/src/api/demo/index.ts index bcef6661..17eea499 100644 --- a/admin/src/api/demo/index.ts +++ b/admin/src/api/demo/index.ts @@ -1,4 +1,5 @@ import type { DemoRoute, HttpMethod, RouteParams } from './types' +import { isDemoActive } from '../client' import { initStore } from './store' import { authRoutes } from './auth' import { servicesRoutes } from './services' @@ -136,6 +137,11 @@ export function setupDemoInterceptor() { : input.url const method = (init?.method || 'GET').toUpperCase() as HttpMethod + // Pass through to real backend if demo mode was deactivated + if (!isDemoActive()) { + return originalFetch(input, init) + } + // Only intercept API routes const isApiRoute = url.startsWith('/admin/') || url.startsWith('/v1/') || url.startsWith('/health') if (!isApiRoute) { diff --git a/admin/src/stores/auth.ts b/admin/src/stores/auth.ts index 65f90b1f..7d005a25 100644 --- a/admin/src/stores/auth.ts +++ b/admin/src/stores/auth.ts @@ -1,6 +1,6 @@ import { defineStore } from 'pinia' import { ref, computed } from 'vue' -import { activateDemoMode, isDemoActive } from '@/api/client' +import { activateDemoMode, isDemoActive, deactivateDemoMode } from '@/api/client' export type UserRole = 'admin' | 'user' | 'web' | 'guest' @@ -189,6 +189,9 @@ export const useAuthStore = defineStore('auth', () => { } function logout() { + if (isDemoActive()) { + deactivateDemoMode() + } token.value = null user.value = null permissions.value = {}