19 lines
557 B
TypeScript
Executable File
19 lines
557 B
TypeScript
Executable File
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()
|
|
}
|
|
})
|