Files
FEDEO/frontend/middleware/auth.global.ts
2026-01-06 12:09:31 +01:00

20 lines
664 B
TypeScript

export default defineNuxtRouteMiddleware(async (to, from) => {
const auth = useAuthStore()
console.log(auth)
if (auth.loading) return
// Wenn nicht eingeloggt → auf /login (außer er will schon dahin)
if (!auth.user && !["/login", "/password-reset"].includes(to.path)) {
return navigateTo("/login")
}
// Wenn eingeloggt → von /login auf /dashboard umleiten
if (auth.user && !auth.user?.must_change_password && to.path === "/login") {
return navigateTo("/")
} else if(auth.user && auth.user.must_change_password && to.path !== "/password-change") {
return navigateTo("/password-change")
}
})