I am trying to create a standard profile page for a user when signed in. I am trying to pass through a variable (email). I am completely clueless on how to pass this variable through to the express route as it would need to be done through a get route as it is pulling back data.
This is what I have.
where the fetch is used.
As you can see I am attempting to send the variable email through here.
getItems() {
try {
const email = window.localStorage.getItem("User");
const data = { email };
fetch("/profile-account-details", email)
.then(recordset => recordset.json())
.then(results => {
this.setState({ AccountDetails: results.recordset });
});
} catch (e) {
console.log(e);
}
}
The route of this fetch through my server.js file. I am simply needing to use this with the stored procedure. All I need essentially need is for the variable to be available here.
app.get("/profile-account-details", function(req, res) {
// connect to your database
sql.connect(config, function(err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.execute("dbo.ProfileAccountDetails", function(err, recordset) {
if (err) console.log(err);
// send records as a response
res.json(recordset);
});
});
});
All I simply want to do is pass through a variable from the get items function and use it within my route. I feel like this is a very simple answer for something I am overlooking.
Any help is greatly appreciated