Monday 12 June 2017

Passport Local Remember Me Strategy

I am trying to create a passport remember me strategy but I am not sure how to call it. My overall strategy is to store two tokens in my database and as cookies on the client's computer and compare then to verify that they are real users. I am currently attempting to pass app.use a passport.authenticate strategy so that I can verify success of failure using my strategy.

In my app.js file I have:

    passport.use('rememberMe',new passportLocal.Strategy({ passReqToCallback: true },
  (req, cb) => {
    //check req.cookies['token']...
    return cb(null, (rememberMe.checkPersistance(req.cookies['token'], req.cookies['statictoken'])));
  }));

app.use((req, res) => passport.authenticate('rememberMe'), (req, res) => {
  //successfully logged in!
})

Note: rememberMe.checkPersistance does the comparison against the database and returns a true or false.

My problem is that I don't think I am using the app.use syntax correctly and I am not sure what the correct way to do it. How do I use passport.authenticate when it isn't in a .POST function?



via Rohit Saxena

No comments:

Post a Comment