28 lines
618 B
TypeScript
28 lines
618 B
TypeScript
export default defineNuxtRouteMiddleware(async(to, from) => {
|
|
const authStore = useAuthStore()
|
|
const token = useCookie('_auth')
|
|
|
|
await authStore.getData()
|
|
|
|
let navigate: any = false
|
|
|
|
/** Belépett */
|
|
if (authStore.user) {
|
|
if (to.fullPath.match(/^\/login/gi)) {
|
|
navigate = '/'
|
|
}
|
|
} else {
|
|
navigate = '/login'
|
|
if (to.fullPath.match(/^\/login/gi)) {
|
|
navigate = false
|
|
}
|
|
if (to.fullPath.match(/^\/page/gi)) {
|
|
navigate = false
|
|
}
|
|
}
|
|
|
|
if (navigate) {
|
|
return navigateTo(navigate)
|
|
}
|
|
})
|