express - PassportJS - Manually Invoking Login After User Update -


i trying auto-login user after updating users email , password information. tried chain local passport authentication after updating table record, endless loop without error. there reason why process run issues despite using same mechanism standard login form?

invited user fills in form update rest of profile , add password:

if(req.body.email && req.body.firstname && req.body.lastname && req.body.password){         models.user.update({             email: req.body.email,             firstname: req.body.firstname,             lastname: req.body.lastname,             password: models.user.generatehash(req.body.password),             authenticationtoken: null         }, {             where: {                 authenticationtoken: req.params.authenticationtoken             }         }).then(function() {             passport.authenticate('local', {                 successredirect: '/app',                 failureredirect: '/login',                 failureflash: 'invalid email or password.'             });         });     } else {         req.flash('error', 'all fields must filled in.');         res.redirect(req.get('referrer'));     } 

passportjs local auth: (query user, organization , stripe account, start session)

passport.use('local', new localstrategy({     passreqtocallback: true,     usernamefield: 'email' }, function(req, email, password, done) {     console.log("login triggered");     var user;     var stripeaccount;     //find user email     models.user.findone({         where: {             email: req.body.email         },         include: [{             model: models.organization,             attributes: ['organizationid']         }]     }).then(function(_user) {         user = _user;          console.log(user);         console.log("this user " + _user)         return models.account.findone({             where: {                 organizationid: user.organizations[0].organizationid             },             attributes: ['subscriptionid']         });      }).then(function(account){         console.log(account);         return stripe.subscriptions.retrieve(account.subscriptionid).then(function(_stripeaccount){             stripeaccount = _stripeaccount;             console.log(_stripeaccount);         }).catch(function(err){             console.log("stripe error");             console.log(err);         });     }).then(function(){         console.log(stripeaccount.status);         console.log("stripe account");         if (!user) {             done(null, false, {                 message: 'the email entered incorrect'             }, console.log("unknown user"));         } else if (!user.validpassword(password)) {             done(null, false, console.log("incorrect password"));         } else {             req.session.organizationid = user.organizations[0].organizationid;             req.session.subscriptionid = stripeaccount.id;             req.session.accountstatus = stripeaccount.status;             done(null, user);         }     }).catch(function(err) {         console.log(err);         console.log("server error");         return done(null, false);     }); })); 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -