Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions admin/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 6 additions & 0 deletions admin/src/api/demo/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion admin/src/stores/auth.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -189,6 +189,9 @@ export const useAuthStore = defineStore('auth', () => {
}

function logout() {
if (isDemoActive()) {
deactivateDemoMode()
}
token.value = null
user.value = null
permissions.value = {}
Expand Down
Loading