I want to get information from my freight Shipment table in order to process other information I need to do in the frontend. But I don't know how to grab the email of the logged-in user using Axios.get() method to use it to query my MySQL DB.
in my frontend, I defined a useState of loggedEmail and I am setting it to the currently logged-in user. how can I pass that to my backend using the GET method?
here is my code:
server:
app.get('/api/freightID', (req, res) => {
const email = req.body. //how would i get the email from the front end to use it in my query?
db.query("SELECT * FROM freight_shipment WHERE user_email = ?", email, (err, result) => {
if(err){
console.log(err)
}
if(result.length > 0 ){
res.send(result);
}
});
});
Frontend:
const [loggedEmail,setLoggedEmail] = useState("");
Axios.defaults.withCredentials = true;
useEffect(() => {
Axios.get('http://localhost:3001/login').then((response) => {
if(response.data.loggedIn == true){
setLoggedEmail(response.data.user[0].email)
setLoginStatus(response.data.loggedIn);
console.log(response.data.loggedIn)
}
})
},[]);
useEffect(() => {
Axios.get("http://localhost:3001/api/freightID").then((response) => {
console.log(response);
})
});