import type { RouteLocationNormalized } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { message } from 'ant-design-vue'

export const authGuard = (to: RouteLocationNormalized) => {
  const userStore = useUserStore()

  if (!userStore.userInfo.tokenValue && to.name !== 'login') {
    message.error('登录失效，请重新登录')
    return {
      name: 'login',
      query: { redirect: to.fullPath },
    }
  }
}
