hoping you all can help me solve this mystery. I’ve created an endpoint for my API:
apiRouter.get("/username", async (req, res) => {
const { username } = req.body;
try {
const user = await getUserByUsername(username);
res.send({ message: "This is your user", user });
console.log("this is user", user);
} catch (error) {
throw error;
}
});
It’s a GET route that should send back the a message and a user object in this fashion when the user interacts with this url path:
http://localhost:3000/api/users/username
When I access the endpoint via, Postman, I get back both the message and the user object. Something that looks like this:
{
"message": "This is your user",
"user": {
"customer_id": 5,
"first_name": "Jessica",
"last_name": "Blue",
"email": "baker@space.com",
"username": "jess1",
"password": "1234",
"address_1": "123 pretty lane",
"address_2": "Apt 31",
"city": "Riverside",
"state": "California"
}
}
However, when I access the route, via my frontend, the message comes back but not the user. I’m using the following method to make the call to the server:
export async function getUserByUsername(username) {
try {
const { data } = await axios.get("/api/users/username", {
username,
});
console.log(data);
return data;
} catch (error) {
throw error;
}
}
I'm really not sure why the user isn’t being sent back with the response. The route works, I’m just not getting back my expected response. I’ve spent a couple hours trying to find a fix with no luck. Any help would be greatly appreciated.enter image description here