I know this is simple but for some reason I can not find the solution for the life of my at all. I am trying to create an axios request and pass data into request to find a single user with a username.
I am passing in a proper username so the username is not the issue. the issue is that the data is undefined on the other side of the request which is made using sequelize.
on postman the request is working properly when I put the following iin the body of the request:
{
"username": "burk"
}
Here is the request:
axios.get('http://localhost:9999/api/users/getUser', {
params: {
username: usereUsername,
}
})
.then(res => {
console.log('successfully grabbed user by username')
}).catch(err => {
})
this is the sequelize portion:
const getUser = (req, res) => {
var id = req.body.username;
console.log(id)
User.findAll({ where: { username: id }})
.then(users => {
console.log(users)
res.send(users);
}).catch(err => {
res.status(500).send({
message: err.message || 'Some error occurred while retrieeing notes.'
});
});
}
const getUser = (req, res) => {
var id = req.body.username;
console.log(id)
User.findAll({ where: { username: id }})
.then(users => {
console.log(users)
res.send(users);
}).catch(err => {
res.status(500).send({
message: err.message || 'Some error occurred while retrieeing notes.'
});
});
}
when i run request through axios, I get this :
undefined
GET /api/users/getUser?username=helm 500 19.836 ms - 74
UPDATE:
this is the postman request I am sending: