护照本地猫鼬错误消息更改

问题描述:

我想使用护照本地猫鼬中间件更改我的错误消息.但这没用:

I want to change my Error Messages with the passport local mongoose middleware. but it didn't work:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var passportLocalMongoose = require('passport-local-mongoose');

var Account = new Schema({
    username: String,
    email: String
});

Account.plugin(passportLocalMongoose,{
    IncorrectUsernameError: 'sdfsd',
    IncorrectPasswordError: 'sdfsd'
});

var User = mongoose.model('Account', Account);

module.exports = User;

多数民众赞成在我的Account.js和登录/注册工作正常

thats my Account.js and login / register works perfect

我的问题是,当我输入错误的用户名/密码时,会出现旧消息用户名或密码不正确".

And my problem is, when i type in a wrong username/password the old message 'incorrect username or password' appears.

在选项中使用 errorMessages 字段:

var options = {
    errorMessages: {
        MissingPasswordError: 'No password was given',
        AttemptTooSoonError: 'Account is currently locked. Try again later',
        TooManyAttemptsError: 'Account locked due to too many failed login attempts',
        NoSaltValueStoredError: 'Authentication not possible. No salt value stored',
        IncorrectPasswordError: 'Password or username are incorrect',
        IncorrectUsernameError: 'Password or username are incorrect',
        MissingUsernameError: 'No username was given',
        UserExistsError: 'A user with the given username is already registered'
    }
};

Account.plugin(passportLocalMongoose,options);