我通过访问我的 PC 的 IP 地址在我的 Iphone 上测试了反应登录页面。当我点击登录按钮时,它每次都会给我以下错误,而不会显示错误 toast。在我电脑的 chrome 浏览器中,它在移动视图中完美运行。
未处理的拒绝(TypeError):未定义不是对象(评估'error.response.data')
这是与 CORS 相关的安全问题吗?如果我将应用程序推送到生产环境,这个错误会得到解决吗?
请帮我弄清楚情况。当我提交登录表单时会调用此 clickSubmit 方法 此图像显示真实移动设备中发生的错误,当我尝试使用另一台笔记本电脑通过同一 wifi 网络访问我的本地服务器时发生同样的事情
const clickSubmit = event => {
event.preventDefault();
setValues({ ...values, buttonText: 'Submitting' });
axios({
method: 'POST',
url: `${process.env.REACT_APP_API}/signin`,
data: { email, password }
}).then(response => {
console.log('SIGNIN SUCCESS', response);
authenticate(response,()=>{
// save the response (user, token) localstorage/cookie
setValues({ ...values, name: '', email: '', password: '', buttonText: 'Submitted' });
// toast.success(`Hey ${response.data.user.name}, Welcome back!`);
isAuth() && isAuth().role === 'admin' ? history.push('/admin') : history.push('/private');
})
})
.catch(error => {
console.log('SIGNIN ERROR', error.response.data);
setValues({ ...values, buttonText: 'Submit' });
toast.error(error.response.data.error);
});
};