Added Frontend
This commit is contained in:
20
frontend/middleware/auth.global.ts
Normal file
20
frontend/middleware/auth.global.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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")
|
||||
}
|
||||
})
|
||||
9
frontend/middleware/redirectToMobileIndex.ts
Normal file
9
frontend/middleware/redirectToMobileIndex.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export default defineNuxtRouteMiddleware(async (to, _from) => {
|
||||
const router = useRouter()
|
||||
|
||||
console.log(useCapacitor().getIsNative())
|
||||
|
||||
if(useCapacitor().getIsNative() && _from.path !== '/mobile') {
|
||||
return router.push('/mobile')
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user