yunohost-portal/middleware/auth.global.ts

18 lines
494 B
TypeScript
Raw Normal View History

2023-07-26 05:24:04 +02:00
import { useIsLoggedIn, useRedirectUrl } from '@/composables/states'
export default defineNuxtRouteMiddleware((to, from) => {
const isLoggedIn = useIsLoggedIn()
2023-07-26 05:24:04 +02:00
useRedirectUrl().value = (from.query.r as string) || null
if (useRedirectUrl().value && to.name === 'login') {
to.query.r = useRedirectUrl().value
}
if (to.name === 'login' && isLoggedIn.value) {
return navigateTo('/')
}
2023-07-26 05:24:04 +02:00
if (to.name !== 'login' && !isLoggedIn.value) {
return navigateTo('/login')
}
})