javascript - How to allow user to try a different email after failure in NodeJS PassportJS? -
currently checking whether or not user has domain name email address using following code. initially, when google authentication window shows, there no option user change email address if logged chrome. when log similar sites google authentication, seemingly recalled being allowed add email address, or of nature.
so, user attempts log on non-lsmsa.edu email address , fails. displays nasty error. how make such user allowed attempt re-login different email address.
if ( profile.emails[0].value.indexof("lsmsa.edu") > -1 ) { var newuser = new user() newuser.google.id = profile.id newuser.google.token = token newuser.google.name = profile.displayname newuser.google.email = profile.emails[0].value newuser.save(function(err) { if (err) throw err return done(null, newuser) }) } else { done(new error("invalid domain. must use lsmsa email address.")) }
check out hd
parameter. makes sure user can sign in proper email.
edit: isn't per-request option. if want use passport-google-oauth
, edit config this:
passport.use(new googlestrategy({ returnurl: 'http://www.example.com/auth/google/return', realm: 'http://www.example.com/', // add hd: 'example.com' }, function(identifier, profile, done) { // blah blah blah, blow pluto, milk cows, eat chocolate, etc. } ));
edit: if reason have have them login again, instead of using hd
, destroy session (req.session.destroy();
), redirect them authentication url (ie. /auth/google
). however, using hd
nicer user experience.
Comments
Post a Comment