aascensao
aascensao

Reputation: 13

Customizing User built-in Model validation

I'm looking for a way to customize the validation for the built-in User Model.

The objective is to be allow users to register an account with the same e-mail but different username.

I've tried to override the Setup Method for the User Model to prevent the validation of the uniqueness of the email property, but unfortunately that was a no go. As for hooks, I've couldn't find any to fulfill my needs.

For reference, the validation occurs in 'loopback/common/models/user.js:556':

  if (!(UserModel.settings.realmRequired || UserModel.settings.realmDelimiter)) {
    UserModel.validatesUniquenessOf('email', {message: 'Email already exists'});
    UserModel.validatesUniquenessOf('username', {message: 'User already exists'});
  }

Is there any way that I can use to disable this e-mail validation?

Thanks in advance.

Upvotes: 0

Views: 911

Answers (1)

Miroslav Bajtoš
Miroslav Bajtoš

Reputation: 10785

Disclaimer: I am a LoopBack team member.

At the moment, it is not possible to allow non-unique user emails. One of the reasons is that User.login supports both email and username, i.e. you can login by entering an email and a password.

In principle, LoopBack can be changed to support your use case, please open a GitHub issue to discuss a possible implementation.

Upvotes: 3

Related Questions