Reputation: 310
I'm using Node.js and intend to use Passport for authentication. However, all of the examples I see online assume the user has already been created. I'd like to know how to create a user's session correctly, after they are saved in the database (I have this part working), so that Passport will recognize them. (I do not want to save the new user and then force them to go to a login page.)
Upvotes: 15
Views: 3116
Reputation: 16000
Just call:
// user is the user instance you just registered and created
req.logIn(user, function(err) {
if (err) return next(err);
// login success!
res.redirect('/home'); // or whereever
});
Documentation for this function is in the code (I need to add it to the guide): https://github.com/jaredhanson/passport/blob/master/lib/http/request.js
Upvotes: 12