mirror of
https://github.com/YunoHost/yunohost-portal.git
synced 2024-09-03 20:06:23 +02:00
23 lines
601 B
TypeScript
23 lines
601 B
TypeScript
import {
|
|
useIsLoggedIn,
|
|
useRedirectUrl,
|
|
useSettings,
|
|
} from '@/composables/states'
|
|
|
|
export default defineNuxtRouteMiddleware(async (to, from) => {
|
|
const isLoggedIn = useIsLoggedIn()
|
|
const settings = await useSettings()
|
|
|
|
useRedirectUrl().value = (from.query.r as string) || null
|
|
if (useRedirectUrl().value && to.name === 'login') {
|
|
to.query.r = useRedirectUrl().value
|
|
}
|
|
|
|
if (to.name === 'login') {
|
|
if (isLoggedIn.value) {
|
|
return navigateTo('/')
|
|
}
|
|
} else if (!isLoggedIn.value && !(to.meta.public && settings.value.public)) {
|
|
return navigateTo('/login')
|
|
}
|
|
})
|