42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
export default defineNuxtRouteMiddleware(async (to, from) => {
|
|
const auth = useAuthStore()
|
|
|
|
// DEBUG: Was sieht die Middleware wirklich?
|
|
console.log("🔒 Middleware Check auf:", to.path)
|
|
console.log("👤 User Status:", auth.user ? "Eingeloggt" : "Gast")
|
|
|
|
// 1. Ausnahme für Workflows
|
|
// WICHTIG: Prüfen ob to.path wirklich mit /workflows beginnt
|
|
if (to.path.startsWith('/workflows')) {
|
|
console.log("✅ Zugriff erlaubt (Public Route)")
|
|
return
|
|
}
|
|
|
|
if (auth.loading) {
|
|
console.log("⏳ Auth lädt noch...")
|
|
return
|
|
}
|
|
|
|
// 2. Wenn nicht eingeloggt
|
|
if (!auth.user) {
|
|
// Erlaube Zugriff auf Login/Reset Seiten
|
|
if (["/login", "/password-reset"].includes(to.path)) {
|
|
return
|
|
}
|
|
|
|
console.log("⛔ Blocked: Not logged in - Redirect to /login")
|
|
return navigateTo("/login")
|
|
}
|
|
|
|
// 3. Wenn eingeloggt
|
|
if (to.path === "/login") {
|
|
if (auth.user.must_change_password) {
|
|
return navigateTo("/password-change")
|
|
}
|
|
return navigateTo("/")
|
|
}
|
|
|
|
if (auth.user.must_change_password && to.path !== "/password-change") {
|
|
return navigateTo("/password-change")
|
|
}
|
|
}) |