A
A
anamorph2017-03-02 13:32:43
Node.js
anamorph, 2017-03-02 13:32:43

How to make a session on Express js if there is already a ready authorization on passport-local-mongoose?

I'm new to this so
here is a ready-made authorization. You need to add sessions
, as I understand it, you need to connect some modules from npm and the code will be where the authorization was successful
if I'm wrong, correct
me at all badly while I understand the session mechanism, and what data will I get as output and how can I work with them later
if you can with to help with this, then thank you,
preferably something easier, in order to wind up less than anyone, the main thing is that it works and is understandable

router.post('/login', function(req, res, next){	 
   passport.authenticate('local', function(err, user, info) {
      if (err) {
        return next(err);
      }
      if (!user) {
        return res.status(401).json({
          err: info
        })
      }
      req.logIn(user, function(err) {
        if (err) {
          return res.status(500).json({
            err: 'Could not log in user'
          });
        }

        res.send(user.username);
      });
    })(req,res,next);
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hikmat Abdunabiev, 2017-03-02
@Khikmat

nodeguide.ru/doc/dailyjs-nodepad/node-tutorial-5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question