From 4aea8b94c3f95c7dcbc3d3270acb89a0a4a20eba Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Tue, 2 Jun 2026 12:00:08 +0200 Subject: [PATCH] Auth-Middleware aus Cookie initialisieren --- frontend/middleware/auth.global.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/middleware/auth.global.ts b/frontend/middleware/auth.global.ts index 9c3f5eb..c9eea0d 100644 --- a/frontend/middleware/auth.global.ts +++ b/frontend/middleware/auth.global.ts @@ -1,6 +1,6 @@ export default defineNuxtRouteMiddleware(async (to, from) => { const auth = useAuthStore() - const isPortalUser = Boolean(auth.profile?.customer_for_portal) + const token = useCookie("token", { path: "/" }).value // DEBUG: Was sieht die Middleware wirklich? console.log("🔒 Middleware Check auf:", to.path) @@ -13,6 +13,13 @@ export default defineNuxtRouteMiddleware(async (to, from) => { return } + if (!auth.user && token && process.client) { + console.log("🔄 Auth-Bootstrap aus Cookie") + await auth.initStore() + } + + const isPortalUser = Boolean(auth.profile?.customer_for_portal) + if (auth.loading) { console.log("⏳ Auth lädt noch...") return