ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.34k stars 8.14k forks source link

不同账号登入导致权限冲突问题 #11312

Open KrisZhengTron opened 3 weeks ago

KrisZhengTron commented 3 weeks ago

使用一个账号打开拥有权限的页面后并登出,使用另一个账号登入时,网页会自动打开之前账号已经开打过的标签,这时如果正在登入的账号没有对应权限就会报错。

目前想到的是当登出时候移除开打的标签页,或者登入时不会自动打开之前登入账号的标签页。 但是不知道哪里去控制标签页的记录。或者提供下其他方法可以避免上面出现的权限问题吗。

wsafight commented 2 weeks ago

修改此处的逻辑即可:

  /**
   * 退出登录,并且将当前的 url 保存
   */
  const loginOut = async () => {
    await outLogin();
    const { search, pathname } = window.location;
    const urlParams = new URL(window.location.href).searchParams;
    /** 此方法会跳转到 redirect 参数所在的位置 */
    const redirect = urlParams.get('redirect');
    // Note: There may be security issues, please note
    if (window.location.pathname !== '/user/login' && !redirect) {
      history.replace({
        pathname: '/user/login',
        search: stringify({
          redirect: pathname + search,
        }),
      });
    }
  };
wsafight commented 2 weeks ago

或者修改此处的逻辑,文件在 page/User/Login/index.tsx

  const handleSubmit = async (values: API.LoginParams) => {
    try {
      // 登录
      const msg = await login({ ...values, type });
      if (msg.status === 'ok') {
        const defaultLoginSuccessMessage = intl.formatMessage({
          id: 'pages.login.success',
          defaultMessage: '登录成功!',
        });
        message.success(defaultLoginSuccessMessage);
        await fetchUserInfo();
        const urlParams = new URL(window.location.href).searchParams;
        // 删除代码
        history.push(urlParams.get('redirect') || '/');
        return;
      }
      console.log(msg);
      // 如果失败去设置用户错误信息
      setUserLoginState(msg);
    } catch (error) {
      const defaultLoginFailureMessage = intl.formatMessage({
        id: 'pages.login.failure',
        defaultMessage: '登录失败,请重试!',
      });
      console.log(error);
      message.error(defaultLoginFailureMessage);
    }
  };
KrisZhengTron commented 1 week ago
image

能写下具体修改代码吗? 知道修改代码位置,之前打开每个页面是有标签留在上面,之前是通过直接标签删除,可以处理。现在因为要求取消标签后,找不到怎么移除打开的页面。 image

之前,是通过直接document 查找.ant-tabs-tab 来找到对应元素删除的。当标签栏移除后,这个方法不能找到对应元素了。