I am using Stormpath for Expressjs (without Passport at the moment) to handle my user registration. I am very concerned about what is the proper way to logout an user.
Before, I always did it through the GET method, however Stormpath explicitly requires a POST call to the /logout page.
I display a user menu only when the user is logged in through Stormpath, this is the super-simple middleware that I have in my router.js in Express:
router.use(stormpath.getUser, function (req, res, next) {
if (req.user) {
req.session.useremail = req.user.email;
}
next();
});
Now, of course in this menu there is the Logout entry. I want my user to click this link to Logout, however I know that when anchor links like <a href="/logout">Logout</a>
are used, a GET request is sent, not a POST.
I have been looking for countless number of ways to redirect a GET request to a POST, but I feel that this is absolutely the wrong way. Also I feel it would make no sense to use a form inside a menu like:
<ul>
<li>User Profile</li>
<li>User Settings</li>
<form action="/logout" method="/post">
<input type="submit">
</form>
</ul>
So the question is: what is the best way to simply logout an user via POST?