angularjs passport.js中间件并没有使用第三个完成的'参数

时间:2016-08-27 20:58:57

标签: javascript angularjs node.js passport.js

这是我的register.js

register.js

 'use strict';
 myApp.controller('RegisterCtrl', function ($scope, $location, alert, $state, $auth, $timeout) {
  $scope.submit = function () {
    $auth.signup({
      email: $scope.email,
      password: $scope.password
    })
      .then(function (res) {
        alert('success', 'Account Created!', 'Welcome, ' + res.data.user.email + '! Please email activate your account in the next several days.');
        $auth.logout();
        $location.path('/')
        return null;
  })
  .catch(function (err) {
        alert('warning', 'Unable to create account :(! The email is already registered.', err.message);
      });
  };
});


localStrategy.js

exports.register = new LocalStrategy(strategyOptions, function (email, password, done) {
  User.findOne({email: email}, function (err, user) {
    if(err) {return done(err);}
    if(user) { return done(null, false, {message: 'This email is duplicate in the database.'});}

    var newUser = new User({
      email: email,
      password: password
    });

    newUser.save(function (err) {
      done(null, newUser);
    })
  });
});

我想使用localStrategy.js上的错误消息,它们是用于传递错误消息的done的第三个参数。这些消息不会被护照中间件使用:

app.post('/register', passport.authenticate('local-register'), function (req, res) {
  emailVerification.send(req.user.email);
  createSendToken(req.user, res);
});


如何强制将错误信息用于护照?


0 个答案:

没有答案