chatgptfreev2bh / src /router /permission.ts
ngoctuanai's picture
Upload 135 files
3424203
raw
history blame
700 Bytes
import type { Router } from 'vue-router'
import { useAuthStoreWithout } from '@/store/modules/auth'
export function setupPageGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
const authStore = useAuthStoreWithout()
if (!authStore.session) {
try {
const data = await authStore.getSession()
if (String(data.auth) === 'false' && authStore.token)
authStore.removeToken()
if (to.path === '/500')
next({ name: 'Root' })
else
next()
}
catch (error) {
if (to.path !== '/500')
next({ name: '500' })
else
next()
}
}
else {
next()
}
})
}