<Form.Item>
<Button type="submit" htmlType="submit" className="login-form-button" onClick={handleSubmit}
>
Log in
</Button>
</Form.Item>
这是在单击按钮时调用提交函数句柄
const handleSubmit = async (e)=>
{
e.preventDefault();
const response = await fetch("http://localhost:5000/login",{
method: "POST",
mode:'no-cors',
headers: {
'content-type':'application/json'
},
body: JSON.stringify({email:credentials.email, password: credentials.password})
});
console.log(response.body);
const json = await response.json();
if(json.success){
window.history.push("/");
}
}
这是我的快速代码,我特灵连接到我的React前端,但反复显示坏的请求
app.post("/login", function(req, res){
const user = new User({
username: req.body.username,
password: req.body.password
});
req.login(user, function(err){
if (err) {
console.log(err);
} else {
passport.authenticate("local")(req, res, function(){
res.redirect("/secrets");
});
}
});
});
我正在特灵连接我的React前端与快速服务器,并期望得到认证的情况下登录。
1条答案
按热度按时间velaa5lx1#
您在html中输入的按钮为大写的
<Button>
。它应该是小写的<button type="submit" htmlType="submit" className="login-form-button" onClick={handleSubmit}>Log in</button>
我想这应该可以。
如果不是,您在控制台中看到的是什么错误?