如何从req中传递email
和password
值Sequelize findAll()
用于查询数据库中的电子邮件和密码。以下是我需要执行的选择查询;
select email, password from user where email="[email protected]";
发送请求时,我在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
在Node中:
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 });
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句