Disconnecting sessions in nodejs Passport.js

I just found out about authentication tokens , which allows stateless / session servers to start with MEAN. It looks amazing.

Currently, I use Passport.jsto authenticate users (via email, Facebook, Google, ...), which stores information in a server session, like all tutorials:

 // required for passport
    app.use(express.session({
        secret : 'superscret',
        expires: new Date(+new Date + settings.session.sessionTimeout),
        store: new MongoStore({})
    })); // session secret
    app.use(passport.initialize());
    app.use(passport.session({}));

It can be used Passport.js, but instead of saving the session, it sends back a token to control whether the user has access.

Question . How to disconnect sessions for the passport? (I know how to send a token and listen to it).

+4
source share
2 answers
+3

passportjs . Docs passport

Passport . - . . , API . , session option to false.

app.get('/api/users/me',
  passport.authenticate('basic', { session: false }),
  function(req, res) {
    res.json({ id: req.user.id, username: req.user.username });
  });
0
source

Source: https://habr.com/ru/post/1598466/


All Articles