| 12345678910111213141516171819202122232425262728 |
- import { getToken } from '@/utils/auth'
- import { useUserStore } from '@/store/user'
- /**
- * 应用启动:若有 Token 则静默拉取用户信息(roles/permissions 供接口侧 checkPermi 使用)
- * 不做页面跳转拦截,页面可自由浏览
- */
- export function syncUserOnLaunch() {
- if (!getToken()) {
- return Promise.resolve()
- }
- const userStore = useUserStore()
- if (userStore.state.roles.length) {
- return Promise.resolve()
- }
- return userStore.fetchUserInfo().catch(() => {
- userStore.fedLogOut()
- })
- }
- /** @deprecated 仅保留兼容,已无路由守卫 */
- export function initRouteGuard() {}
- /** @deprecated 请使用 syncUserOnLaunch */
- export function bootstrapAuth() {
- return syncUserOnLaunch()
- }
|