Closed wuchencm closed 8 months ago
` 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('登录失败,请重试'); }
};`
后端返回的数据有问题,有的时候没有返回数据
🐛 bug 描述
📷 复现步骤 | Recurrence steps
🏞 期望结果 | Expected results
💻 复现代码 | Recurrence code
` const fetchUserInfo = async () => { const userInfo = await initialState?.fetchUserInfo?.(); if (userInfo) { flushSync(() => { setInitialState((s) => ({ ...s, currentUser: userInfo, })); });
};
const handleSubmit = async (values: API.LoginParams) => {
};`
© 版本信息
🚑 其他信息