3

I really don't know why the Post Request and the following redirect and Rendering is not working. Here my Code:

HTML:

$(function () {
    $LogOutButton.click(function () {
        $.ajax({
            type: "POST",
            url: "/logout"
        });
    });
});

APP.js

app.get('/login',function (req, res) {

if (req.isAuthenticated() && req.user.name != "admin") { 

res.redirect('/ImpleniaViewer');
}
else {res.render('Login.hbs');}});

app.get('/logout', function (req, res) {

res.send("Hallo");

});

app.post('/logout', function (req, res) {
req.session.destroy(function (err) {
res.redirect('/logout'); //Inside a callback… bulletproof!
});
});
dabuchera
  • 79
  • 5

1 Answers1

0

Simply use req.logout() to remove req.user from your request local alongside your code.

Your code.

app.post("/logout", function(req, res) {
    req.logout();
    req.session.destroy();
    res.redirect("/logout");
});
Asghar Musani
  • 568
  • 4
  • 20