-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User model without email or without username #1137
Comments
Hello, could you please give a ETA for this feature will be supported? |
At this point, you can use module.exports = function(app) {
delete app.models.User.validations.email;
}; |
Thanks Raymond, this is a acceptable workaround. |
but "login failed as the email has not been verified" |
|
So I looked at the roadmap and noticed it had an (8) next to it...does this represent the effort to complete it? What is the likelihood of this getting done? When is the target for this getting done? |
@gonzofish I am afraid we don't have any target date for this. |
+1 |
2 similar comments
+1 |
+1 |
Please note that the workaround above by @raymondfeng will remove all validations from the user model for email, including uniqueness, presence, format, and any additional validations defined in Assuming that In module.exports = function(user) {
// Remove existing validations for email
delete user.validations.email;
// Adds email format validation
// Note custom validator because validatesFormat with regex will return false on a null value
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
user.validate('email', function (err) { if (!re.test(this.email) && this.email !== undefined) err(); }, {message: 'Email format is invalid'});
// Adds email uniqueness validation
user.validatesUniquenessOf('email', {message: 'Email already exists'});
} |
@codyolsen +1 - I was struggling with this today, and you just saved me. However, the format one still gives me an error if the email is null. Did this one work for you? |
@jonathanwoahn Yeah it's working for me. If you have more troubles you might be able to find more specific help on the loopback gitter. |
Tank you so much @raymondfeng, you save my day :), just me worry about leaving this User email and unique in the database for users not logarem with similar credentials. |
In your built-in user model inside, a lot of places to use the mailbox this thing, so can not simply delete this thing. Delete will influence to reset the password, and even affect the secret key generation, I think we should provide an optional project, configuration into the phone number or e-mail address, user name is to make configuration options for unique personality, but need to choose a as a unique ID. |
This is a great workaround ... and when I updated the versions, unfortunately this was no longer a work around so I rolled back to the versions that are part of this example. Is there a fix for the later packages?
|
@codyolsen, thank you for this tip. You can also use isemail library, which is used by loopback at this line for email validation, as shown here: 'use strict';
var isEmail = require('isemail');
module.exports = function(user) {
delete user.validations.email;
user.validate('email', function (err) { if ( this.email !== undefined && !isEmail(this.email)) err(); }, {message: 'Email format is invalid'});
// Adds email uniqueness validation
user.validatesUniquenessOf('email', {message: 'Email already exists'});
}; |
Raymond's workaround is fine for validation, but the built-in User model still has email required as discussed in issue #2125, which requires more workarounds. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
what if i have custom method which have required` 'true' ?
then how to remove its required field. |
Another way ?? i want to delete the field email in the table. |
LoopBack should allow developers to configure the
User
model to use only email+password or only username+password for logging in.See #791, #820 and "Pluggable authentication providers decoupled from the user model" in the Roadmap
The text was updated successfully, but these errors were encountered: