export default (nuxtContext) => {
  return new Promise((resolve, reject) => {
    const { $auth, route, store } = nuxtContext;
    // 判断路由中携带token吗
    const token = route?.query?.token;
    if (process.env.SSO === "1" && Boolean(token)) {
      Promise.all([
        // 设置token
        $auth.setUserToken(token),
        // 用户菜单
        store.dispatch("fetchSysInfoByToken"),
      ])
        .then(() => {
          // 缓存上一次登录用户id
          store.commit("account/SET_USER_ID", store.state.auth.user.user.id);
          resolve();
        })
        .catch((_err) => {
          reject(_err);
        });
    } else {
      resolve();
    }
  });
};
