For some reason I am getting this error when I try to login to my application: "unspecified "error" event. (Incorrect arguments)"
This only happens when I attempt to login so I'm assuming there's an error somewhere in my login function and or user Schema.
var userSchema = new mongoose.Schema({
username: String,
password: String,
datapoint: String,
email: String,
resetPasswordToken: String,
resetPasswordExpires: Date
});
userSchema.pre('save', function(next) {
var user = this;
if (!user.isModified('password')) return next();
bcrypt.genSalt(10, function(err, salt) {
if (err) return next(err);
bcrypt.hash(user.password, salt, null, function(err, hash) {
if (err) return next(err);
user.password = hash;
next();
});
});
});
userSchema.methods.comparePassword = function(password) {
return bcrypt.compareSync(password, this.password);
}
app.post('/login', passport.authenticate('local-login', {
successRedirect: '/',
failureRedirect: '/login',
}));
passport.use('local-login', new LocalStrategy({
usernameField: 'username',
passwordField: 'password',
passReqToCallback: true
}, function(req, username, password, done) {
User.findOne({ username: username}, function(err, user) {
if (err) return done(err);
if (!user) {
return done(null, false, req.flash('error', 'No user has been found'));
}
if (!user.comparePassword(password)) {
return done(null, false, req.flash('error',
'Wrong password. Please check Caps Lock button, capital letters and retype the password.'));
}
return done(null, user);
});
}
));
via AndrewLeonardi
No comments:
Post a Comment