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.
26 lines
622 B
TypeScript
26 lines
622 B
TypeScript
2 years ago
|
import type { Router } from 'vue-router'
|
||
|
import { useAuthStoreWithout } from '@/store/modules/auth'
|
||
|
|
||
|
export function setupPageGuard(router: Router) {
|
||
|
router.beforeEach(async (from, to, next) => {
|
||
|
const authStore = useAuthStoreWithout()
|
||
|
if (!authStore.session) {
|
||
|
try {
|
||
|
const data = await authStore.getSession()
|
||
|
if (String(data.auth) === 'false' && authStore.token)
|
||
|
authStore.removeToken()
|
||
|
next()
|
||
|
}
|
||
|
catch (error) {
|
||
|
if (from.path !== '/500')
|
||
|
next({ name: '500' })
|
||
|
else
|
||
|
next()
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
next()
|
||
|
}
|
||
|
})
|
||
|
}
|