From e9504e21e746686919683cc6e1b36db85ed96688 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Tue, 2 Jun 2026 12:14:16 +0200 Subject: [PATCH] =?UTF-8?q?Token=20f=C3=BCr=20Reload=20zus=C3=A4tzlich=20l?= =?UTF-8?q?okal=20sichern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/plugins/api.ts | 3 ++- frontend/stores/auth.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/plugins/api.ts b/frontend/plugins/api.ts index f42f0f7..82efaaa 100644 --- a/frontend/plugins/api.ts +++ b/frontend/plugins/api.ts @@ -8,7 +8,8 @@ export default defineNuxtPlugin(() => { credentials: "include", async onRequest({ options }) { - const token = useCookie("token", { path: "/" }).value + const auth = useAuthStore() + const token = auth.getStoredToken() // Falls im Request explizit ein anderer JWT übergeben wird if (options.context?.jwt) { diff --git a/frontend/stores/auth.ts b/frontend/stores/auth.ts index c4eef21..004f89d 100644 --- a/frontend/stores/auth.ts +++ b/frontend/stores/auth.ts @@ -43,7 +43,11 @@ export const useAuthStore = defineStore("auth", { .map((part) => part.trim()) .find((part) => part.startsWith("token=")) - return tokenCookie ? decodeURIComponent(tokenCookie.slice("token=".length)) : null + if (tokenCookie) { + return decodeURIComponent(tokenCookie.slice("token=".length)) + } + + return localStorage.getItem("token") }, clearScopedTokenCookies() { @@ -164,6 +168,14 @@ export const useAuthStore = defineStore("auth", { this.clearScopedTokenCookies() this.tokenCookie().value = token + if (process.client) { + if (token) { + localStorage.setItem("token", token) + } else { + localStorage.removeItem("token") + } + } + if (!token) { this.clearSessionTimers() this.sessionWarningVisible = false