W
W
Wasya UK2018-07-18 18:43:10
Node.js
Wasya UK, 2018-07-18 18:43:10

How to delete a session from the database?

I use connect-session-sequelize to authorize the user, but the session is not deleted after /logout, the page is updated and the passport considers the user authorized. I'm thinking of adding a user id to the table, and then searching for and deleting the session from the database.
1) Is it right to do this?
2) Maybe I did something wrong, what else could be the problem? Here is the code:

app.get('/logout', function(req, res) {
  console.log('logout', req.session); // cookie { passport: {...}}
  req.logout(); // cookie { no_passport}
  req.session.destroy(); // не удаляет
  res.redirect('/');
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wasya UK, 2018-08-14
@dmc1989

module.exports.logout = (req, res) => {
  console.log('logout', req.session);
  req.logout();
  req.session.destroy(() => {
    res.redirect('/');
  });
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question