You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
400 B
Plaintext

import type { Router } from 'vue-router'
import { useUserStore } from '@/stores/user'
export function setupLoginGuard(router: Router) {
const webUser = useUserStore()
router.beforeEach((to, from, next) => {
if (webUser.getToken && to.path === '/login') {
next('/')
return
}
if(!webUser.getToken && to.path !== '/login') {
next("/login");
return;
}
next();
})
}