ant-design / ant-design-pro

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

🐛 [BUG] 登录的时候须要点击多次才能登录成功 #11113

Closed wuchencm closed 8 months ago

wuchencm commented 8 months ago

🐛 bug 描述

📷 复现步骤 | Recurrence steps

🏞 期望结果 | Expected results

💻 复现代码 | Recurrence code

` const fetchUserInfo = async () => { const userInfo = await initialState?.fetchUserInfo?.(); if (userInfo) { flushSync(() => { setInitialState((s) => ({ ...s, currentUser: userInfo, })); });

  return userInfo
}

};

const handleSubmit = async (values: API.LoginParams) => {

try {
  // 登录
  const msg = await login({...values, type});
  if (msg.success) {
    //写入token
    const token = msg?.data as string
    localStorage.setItem("jwt_token", token)
    message.success('登录成功');
    //登录成功后获取用户信息
    const current = await fetchUserInfo();
    //登录成功后跳转,设置延迟
    setTimeout(() => {
      console.log(current)
      if(current !== undefined){
        const urlParams = new URL(window.location.href).searchParams;
        history.push(urlParams.get('redirect') || '/');
      }
    }, 1000)

    return;
  }

  // 如果失败去设置用户错误信息
  setUserLoginState(msg);
} catch (error) {
  console.log(error)
  message.error('登录失败,请重试');
}

};`

© 版本信息

🚑 其他信息

wuchencm commented 8 months ago

后端返回的数据有问题,有的时候没有返回数据