sebbounltd
sebbounltd

Reputation: 31

passport-local-mongoose Error message change

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;

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.

Upvotes: 2

Views: 3782

Answers (3)

Rajat
Rajat

Reputation: 526

You can do it as follow:

Account.plugin(passportLocalMongoose, { usernameField: 'email', errorMessages : { UserExistsError : 'A user with the given email is already registered.' } });

Upvotes: -1

jordiburgos
jordiburgos

Reputation: 6302

Use the errorMessages field in the options:

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);

Upvotes: 10

alrashidmtz
alrashidmtz

Reputation: 9

you can change the options



    var options = {
            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);

Upvotes: -2

Related Questions