yunohost-portal/middleware/auth.global.ts

23 lines
582 B
TypeScript
Raw Normal View History

import {
useIsLoggedIn,
useRedirectUrl,
useSettings,
} from '@/composables/states'
export default defineNuxtRouteMiddleware(async (to, from) => {
const isLoggedIn = useIsLoggedIn()
const settings = await useSettings()
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('/')
}
if (!isLoggedIn.value && !(to.meta.public && settings.value.public)) {
2023-07-26 05:24:04 +02:00
return navigateTo('/login')
}
})