gpt4 book ai didi

javascript - passport-local-mongoose 错误消息更改

转载 作者:行者123 更新时间:2023-11-29 21:32:21 31 4
gpt4 key购买 nike

我想用 passport 本地 mongoose 中间件更改我的错误消息。但它没有用:

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 和登录/注册的完美

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

最佳答案

在选项中使用 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);

关于javascript - passport-local-mongoose 错误消息更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35856018/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com