@@ -1,20 +1,42 @@
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
const auth = useAuthStore()
|
||||
|
||||
console.log(auth)
|
||||
// DEBUG: Was sieht die Middleware wirklich?
|
||||
console.log("🔒 Middleware Check auf:", to.path)
|
||||
console.log("👤 User Status:", auth.user ? "Eingeloggt" : "Gast")
|
||||
|
||||
if (auth.loading) return
|
||||
// 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
|
||||
}
|
||||
|
||||
// Wenn nicht eingeloggt → auf /login (außer er will schon dahin)
|
||||
if (!auth.user && !["/login", "/password-reset"].includes(to.path)) {
|
||||
// 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")
|
||||
}
|
||||
|
||||
// Wenn eingeloggt → von /login auf /dashboard umleiten
|
||||
if (auth.user && !auth.user?.must_change_password && to.path === "/login") {
|
||||
// 3. Wenn eingeloggt
|
||||
if (to.path === "/login") {
|
||||
if (auth.user.must_change_password) {
|
||||
return navigateTo("/password-change")
|
||||
}
|
||||
return navigateTo("/")
|
||||
} else if(auth.user && auth.user.must_change_password && to.path !== "/password-change") {
|
||||
}
|
||||
|
||||
if (auth.user.must_change_password && to.path !== "/password-change") {
|
||||
return navigateTo("/password-change")
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user