Allowing users to log out
Users will also expect us to provide a way to log out of our application. Passport makes this easy by adding a logout
function to the request. We just need to make use of this in one of our routes here src/routes/index.js
:
router.post('/logout', function(req, res){ req.logout(); res.redirect('/'); });
We can add a log out button to our view to make use of this new route as in src/views/index.hjs
:
{{#loggedIn}} <form action="/logout" method="POST"> <input type="submit" value="Log out" /> </form> <h3>Profile</h3>