Good day/night,
I am making a store page right now. I need send two things in the fetch call, the list of items and the id of the user. From my nodejs code I pass my userid like this:
router.get('/testing', async (req, res) => {
if (req.user) {
let query = await User.findOne({ userid: req.user.steamid })
res.render('testing', {
user: req.user,
balance: (query.balance/100),
steamid: req.user.steamid
})
} else {
res.redirect('/')
}
});
I have my HTML file and my JS code separate. In my HTML I normally call the variable using the handlebars. Eg:
<a class="nav-link" >Balance: ${{balance}}</a>
However one thing I don't understand is how can I use these parameters in my JS code? Which is in an external file. Do I set the variable in the HTML first? If so wouldn't that mean someone could just change it to say my id and then I'd lose my balance? Would I need to use bcrypt to hash the userids? Would really appreciate some advice! :)