feat(frontend): add debugMode global variable to store debug mode state
This commit is contained in:
@@ -2,10 +2,18 @@ import { createApp } from 'vue';
|
||||
import App from './App.vue';
|
||||
import router from './router/index.js';
|
||||
import { initTheme } from './utils/theme.js';
|
||||
import { isLoggedIn } from './utils/auth.js';
|
||||
import { loadDebugMode } from './utils/runtime.js';
|
||||
import '@fortawesome/fontawesome-free/css/all.min.css';
|
||||
import './styles/theme.css';
|
||||
import './styles/ui.css';
|
||||
|
||||
initTheme();
|
||||
|
||||
// A persisted session can fetch the runtime flags right away; a fresh visitor
|
||||
// has no token yet and picks them up after signing in.
|
||||
if (isLoggedIn()) {
|
||||
loadDebugMode();
|
||||
}
|
||||
|
||||
createApp(App).use(router).mount('#app');
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { ref } from 'vue';
|
||||
import { settingsApi } from '../api/index.js';
|
||||
|
||||
// Runtime flags mirrored from the backend config so any view can read them
|
||||
// without refetching the whole config.
|
||||
|
||||
// debugMode mirrors system.debugMode from the global config (config.json).
|
||||
export const debugMode = ref(false);
|
||||
|
||||
// loadDebugMode reads the global config and mirrors system.debugMode into the
|
||||
// `debugMode` global. The endpoint needs an admin session, so callers only
|
||||
// invoke it once logged in; a failed request keeps the current value.
|
||||
export async function loadDebugMode() {
|
||||
try {
|
||||
const res = await settingsApi.get('global');
|
||||
const config = (res && res.data && res.data.config) || {};
|
||||
const system = config.system || {};
|
||||
debugMode.value = !!system.debugMode;
|
||||
} catch {
|
||||
// Non-fatal: the flag simply keeps its current value.
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { reactive, ref, computed } from 'vue';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { authApi } from '../api/index.js';
|
||||
import { setSession } from '../utils/auth.js';
|
||||
import { loadDebugMode } from '../utils/runtime.js';
|
||||
import { toast } from '../utils/toast.js';
|
||||
|
||||
const router = useRouter();
|
||||
@@ -23,6 +24,8 @@ function goTo(target) {
|
||||
|
||||
function afterLogin(token, user) {
|
||||
setSession(token, user);
|
||||
// The settings endpoint requires the token we just stored.
|
||||
loadDebugMode();
|
||||
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : '/overview';
|
||||
router.push(redirect);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user