jeudi 19 février 2015

Passport js authenticate by url

I'm using Express JS and Passport JS for my app.


I want to give a new user the opportunity to automatically login, once, by a specific URL. I can get the user from the database with the information from the URL, so I have an User object (with id, email, hashed password etc.) but I don't know how I can use passport to authenticate the user and login.


I tried executing below function with the user object I got from the database:



req.login(user, function(err) {
if (err) { return next(err); }
return res.redirect('/users/' + req.user.username);
});


source: http://ift.tt/1bPQo4n


But that didn't work. Guess it's just because the user object contains the hashed password... Anyone who ever tried this before and can tell me how it works?


Aucun commentaire:

Enregistrer un commentaire