angularjs - PassportJS with NodeJS not returning errors (MEAN stack) -
i'm running mean stack passportjs authentication, , i'm having issue signup module interacting angular controller. basically, errorcallback never called, , i'm not sure how use passport done() implementation.
i have basic signup form upon submission, calls request:
$http.post('/api/signup', { name: $scope.user.name, email: $scope.user.email, password: $scope.user.password, usersince: new date().now }).then( function successcallback(res) { $rootscope.message = 'account created'; console.log('success'+res); console.dir(res,{depth:5}); $location.url('/signupconf'); }, function errorcallback(res) { $rootscope.message = 'failure, see console'; console.log('error: '+res); console.dir(res,{depth:5}); $location.url('/'); }); with express route:
app.post('/api/signup', passport.authenticate('local-signup'),function(req, res) { console.log('user: ' + req.user.email); }); and passport (adapted scotch.io tut) module, abridged little:
passport.use('local-signup', new localstrategy({ usernamefield : 'email', passwordfield : 'password', passreqtocallback : true }, function(req, email, password, done) { console.log("signup request: "+email); process.nexttick(function() { user.findone({ 'email' : email }, function(err, user) { if (err) { return done(err); } // check see if theres user email if (user) { console.log("user not created, exsists: "+user); return done(err, false, {message: 'username exsists.'}); } else { // if there no user email // create user var newuser = new user(); //a bunch of data creation here newuser.save(function(err) { if (err) {throw err;} console.log("sucessfully created: "+newuser); return done(null, newuser); }); } }); }); })); everything runs fine, users created corrected, , if user given email exists, new 1 isn't written on it. however, no matter what, successcallback called. when username exist, can see 401 error in browser console. when bad request (i.e. not fields filled), 400 error.
all server side console.logs work fine, leading me think there's wrong in angular frontend, or how backend responding request.
(scotch.io tutorial credit: https://scotch.io/tutorials/easy-node-authentication-setup-and-local)
the problem sort of staring me in face, in route handling.
app.post('/api/signup', function(req, res, next) { passport.authenticate('local-signup', function(err,user,response) { //handle responses based on state of user , err }) (req, res, next); });
Comments
Post a Comment