Saturday, 3 June 2017

Running an passed function and passport.authenticate

hope your day is going well. I want both the function that sets the JWT and the passport.authenticate to run but only the former is running. Is there a way I can have both run?

   router.post('/login',(req, res, next) => {

        console.log(req.body.username);
        const userEmail = req.body.username;

        User.getUserByEmail(userEmail, function(err, user){


            const token = jwt.sign(user, config.secret, {
                             expiresIn: 604800 // 1 week
                         });
            new Cookies(req,res).set('access_tokenx',token,{
                httpOnly: true,
                secure: false      
            });
            return res.send();

        });
    },
      passport.authenticate('local', {successRedirect:'/', failureRedirect:'/users/login',failureFlash: true}),
      function(req, res) {
        res.redirect('/');
      });

Thanks in advance, Ed.



via Ed Lynch

No comments:

Post a Comment