I am building a resend verification email button for the logged in users. My plan is to let the user click the button on the profile page, and it will send the email directly to the user's email address.
It seems that I am stuck with sending the user's data to the backend code when clicking the button.
I got undefined
when I check the req.params.id
in the route setting.
Here is my route:
//route for requsting verification email
router.post("/verify", middleware.isLoggedIn, async(req, res) => {
console.log(req.params.id);
})
Here is the ejs/html:
<form action="/verify" method="POST">
<input type="submit" class="btn btn-success btn-sm" value="Verify">
</form>
I think my html code needs some onClick event to explicitly send the user's id to the server code in order to find the correct user. However, I have no clue how to make this. Thank you in advance for any help!
UPDATE
Thanks to @Mizibi for helping me understand the difference between req.params
and req.body
.
SO what I did is to add another hidden input tag in the form like this:
<form action="/verify" method="POST">
<input type="hidden" name="id" value="<%= currentUser.id %>" >
<input type="submit" class="btn btn-success btn-sm" value="Verify">
</form>
And I changed the backend req.params.id
to req.body.id
, This will pass the currentUser's id to the backend code for finding the user and do the operations.