From 18b5f0f0e171489b99002ad1ea269d031e62dea8 Mon Sep 17 00:00:00 2001 From: Arthur Lefebvre Date: Tue, 24 Feb 2026 19:02:38 +0100 Subject: [PATCH] Demo mode: automatically connect as demo user --- front/src/AppNavBar.vue | 27 +++++++++++++++++++------ front/src/api.js | 4 ++-- internal/apitest/get_appinfo_test.go | 1 + internal/config/config.go | 2 ++ internal/dto/out.go | 1 + internal/routes/appinfo.go | 5 ++++- internal/routes/userlogin.go | 30 ++++++++++++++++++---------- 7 files changed, 50 insertions(+), 20 deletions(-) diff --git a/front/src/AppNavBar.vue b/front/src/AppNavBar.vue index b74c5e3..bbae086 100644 --- a/front/src/AppNavBar.vue +++ b/front/src/AppNavBar.vue @@ -4,7 +4,7 @@ import NavBarSearch from './NavBarSearch.vue' import BarcodeModal from './BarcodeModal.vue' import { useAuthStore } from './auth.store.js' - import { getAppInfo } from './api.js' + import { getAppInfo, postLogin } from './api.js' import { onMounted } from 'vue' const authStore = useAuthStore(); @@ -21,8 +21,23 @@ const appInfo = ref(null); const appInfoErr = ref(null); + async function logInIfDemoMode(demoMode) { + if (!demoMode) { + return; + } + + const demouser = ref({ + username: "demo", + password: "" + }); + const res = await postLogin(demouser) + const json = await res.json(); + await useAuthStore().login({username: demouser.value.username, token: json["token"]}) + } + onMounted(() => { - getAppInfo(appInfo, appInfoErr); + getAppInfo(appInfo, appInfoErr) + .then(() => logInIfDemoMode(appInfo.value.demoMode)); }) @@ -62,7 +77,7 @@ {{ $t('navbar.addbook')}} -