Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Login strategy. Enable passing through of the req object by setting passReqToCallback to true.
passport.use(new Strategy({ passReqToCallback: true },
function (req,username, password, done) {
let user = your_user_auth(username,password); // returns the user object if valid, otherwise null
if(user)
// Extract the redirect hash from the request body and store it in the request session object
req.session.redirect_url = req.body.url;
return done(null, user);
}
return done(null, false);
});
}
));
// The route where you POST the form to.
app.post('/web-login',
passport.authenticate('local', { failureRedirect: '/login' }), // This is the strategy we just defined
function(req, res, info) {
// If there is a redirect stored in the req session object, use it.
if (req.session.redirect_url) return res.redirect('/cms/' + req.session.redirect_url);
res.redirect('/cms/' + redirect);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.