finance-pay-admin/pc/middleware/route.global.ts

19 lines
557 B
TypeScript
Raw Normal View History

2023-11-08 18:02:55 +08:00
import { useAppStore } from '~~/stores/app'
import { useUserStore } from '~~/stores/user'
import { isEmptyObject } from '~~/utils/validate'
export default defineNuxtRouteMiddleware(async (to, from) => {
const userStore = useUserStore()
const appStore = useAppStore()
try {
if (isEmptyObject(appStore.config)) {
await appStore.getConfig()
}
if (userStore.isLogin && isEmptyObject(userStore.userInfo)) {
await userStore.getUser()
}
} catch (error) {
userStore.$reset()
}
})