2023-07-26 05:24:04 +02:00
|
|
|
import { useIsLoggedIn, useRedirectUrl } from '@/composables/states'
|
2023-07-20 17:36:08 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-07-20 17:36:08 +02:00
|
|
|
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')
|
2023-07-20 17:36:08 +02:00
|
|
|
}
|
|
|
|
})
|