gpt4 book ai didi

reactjs - 如何将 req 值传递给 Sequelize findAll

转载 作者:行者123 更新时间:2023-12-03 22:19:29 25 4
gpt4 key购买 nike

如何使用 email 从 req 传递 passwordSequelize findAll() 值以查询数据库中的电子邮件和密码。下面是我需要执行的选择查询;
select email, password from user where email="some_email@testmail.com";
发送请求时,我在 n/w 选项卡响应中收到以下错误:

{"message":"WHERE 参数\"email\"具有无效的\"undefined\"值"}
server.js

app.get('/service/login', async (req, res) => {
try {
const loginData = await UserModel.findAll({ where: { email: req.body.email, password: req.body.password} });
console.log(loginData);
res.status(200).json({ loginData });
} catch (e) {
res.status(500).json({ message: e.message });
}
});
login.js
 const handleSubmit = (e) => {
e.preventDefault()
const fetchData = async () => {
try {
const res = await Axios.get('http://localhost:8000/service/login');
setLoginData(res.data.loginData);
console.log("Get data from database:"+loginData.password);
} catch (e) {
console.log(e);
}
}
fetchData();
};

最佳答案

get 方法转换为 post
在节点:

app.post('/service/login'
// then you will be able to access `req.body`

在 react 中:
// you were not even passing the email and password
await Axios.post('http://localhost:8000/service/login',{ email , password });

关于reactjs - 如何将 req 值传递给 Sequelize findAll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62033415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com