import router from './'
import * as AuthUtils from '@/utils/auth'
// 路由不重定向白名单
const whiteList = [
    '/sign-in',
    '/social-login',
    '/auth-redirect',
  ]

  router.beforeEach(async (to, from, next) => {
    if (AuthUtils.getAccessToken()) {
        if (to.path === '/sign-in') {
            next({ path: '/' })
          }
    } else {
        if (whiteList.indexOf(to.path) !== -1) {
            next()
        } else {
            next(`/sign-in?redirect=${to.fullPath}`) // 否则全部重定向到登录页
        }
    }
  })