Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KrisZhengTron opened this issue Aug 19, 2024 · 3 comments
Open

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

KrisZhengTron opened this issue Aug 19, 2024 · 3 comments

Comments

@KrisZhengTron
Copy link

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

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

@wsafight
Copy link
Contributor

修改此处的逻辑即可:

  /**
   * 退出登录,并且将当前的 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
Copy link
Contributor

或者修改此处的逻辑,文件在 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
Copy link
Author

image 能写下具体修改代码吗? 知道修改代码位置,之前打开每个页面是有标签留在上面,之前是通过直接标签删除,可以处理。现在因为要求取消标签后,找不到怎么移除打开的页面。 ![image](https://github.com/user-attachments/assets/bfeece73-47df-46f3-84c4-fb7e34730145)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants