You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is not possible to drop the uniqueness constraint on User email. User.login supports both username and email, and if email was not unique, it would not be possible to tell which user is logging in.
But @bajtos , the mere fact that User.login supports both methods implies there are two use-cases it handles: one is where username is unique, and the other is where email is unique. It should be straightforward to choose which use-case you want, and be assured of the semantics only in that one.
So, can I really not override the uniqueness of email if I never log my users in using email? My derived model (e.g. MyUser) would not offer an email-based login, only realm + username.
Please can you confirm that it's still true there's no solution for me? It's really hard to believe I would have to build my own User class from the ground up just to do what otherwise seems very straightforward override behavior.
(And before you ask -- of course it makes sense to have multiple or even no email addresses associated with User. There are many examples, among them: (1) migrating accounts from an old system where username was unique and not email address, and (2) using the passport plugin to link users' accounts to other services, i.e. where there is no email-based login provided at all.)
Email as pseudo-primary key to login is mostly a thing of the past. It would actually be smart to consider dropping email altogether in the User model and if people want to add a relationship between Users and emails, let them add it in themselves in their derived model. I will never use any of Loopback's built-in User email confirmation dialog, for example -- again, because I won't require email at all in many cases.
So for my use-case, am I forced to either build my own User model from the ground up, or to finagle fake email addresses that are unique just to satisfy this constraint?
Am I really in the minority wanting this functionality?
Thanks.
Steve
Reacted by Pulkit Singhal, Sabrina and Mark Santiago
Ah hah -- man, sometimes it's really hard piecing together what's what from a Google search given how active development is on this (though, that's a good thing of course).
Anyway, I think I figured out that in fact you do correctly support this dichotomy of uses in the current implementation of the built-in User model (as of 2016, anyway). I see in the code, all I needed to do was add "realmRequired": true to the options object in my derived user model, e.g.:
With realmRequired: true, email is not required to be unique. Excellent!
So that's pretty much just what I needed in my case (I am fine requiring realm, as I said above, it makes total sense that realm+username would replace email as the primary-ish key.
Thanks a lot -- I'm good to go. Though as usual, maybe there's something I can do to help improve the docs, will look at it again later and update this if so with proposed improvement (or not :-) ).
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.
Of course, if you replace the mailbox with a phone number, a lot of places need to change, first of all, you may not need to change the token, but the certification section has to make a lot of changes.
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.
Of course, if you replace the mailbox with a phone number, a lot of places need to change, first of all, you may not need to change the token, but the certification section has to make a lot of changes.
In my example code in my previous comment, I am not changing the built-in user model, I'm changing MyModel which inherited from user model. So no harm done, I hope you agree @buzai? Unless I'm nuking a shared prototype unknowingly? Let me know.
@pulkitsinghal , I'm not saying you destroy something, I think if you do not use it's own mailbox, then how to generate the user's token it, then you have to write your own method of generating token, there is a lot of built-in methods you can not use the fact, I think if we do so, not as a direct write a model, rather than inherited user. I look at the code inside the user's login and also implements several methods to create a similar, but those methods and mailbox properties coupled together.
Activity
Spark-star commentedon Nov 28, 2014
I have the same question.
I have resolved it by setting default value in beforecreate hook.
2014-11-28 16:46 GMT+08:00 Salvatore notifications@github.com:
diasalvatore commentedon Nov 28, 2014
Ok, it could be a workaround for the password, but what about email uniqueness? I would allow multiple accounts with same email.
bajtos commentedon Dec 4, 2014
It is not possible to drop the uniqueness constraint on User email.
User.loginsupports bothusernameandemail, and ifemailwas not unique, it would not be possible to tell which user is logging in.slgoldberg commentedon Feb 20, 2016
But @bajtos , the mere fact that
User.loginsupports both methods implies there are two use-cases it handles: one is whereusernameis unique, and the other is whereemailis unique. It should be straightforward to choose which use-case you want, and be assured of the semantics only in that one.So, can I really not override the uniqueness of
emailif I never log my users in usingemail? My derived model (e.g.MyUser) would not offer an email-based login, onlyrealm+username.Please can you confirm that it's still true there's no solution for me? It's really hard to believe I would have to build my own
Userclass from the ground up just to do what otherwise seems very straightforward override behavior.(And before you ask -- of course it makes sense to have multiple or even no email addresses associated with User. There are many examples, among them: (1) migrating accounts from an old system where
usernamewas unique and notemailaddress, and (2) using thepassportplugin to link users' accounts to other services, i.e. where there is no email-based login provided at all.)Emailas pseudo-primary key to login is mostly a thing of the past. It would actually be smart to consider dropping email altogether in theUsermodel and if people want to add a relationship betweenUsers andemails, let them add it in themselves in their derived model. I will never use any of Loopback's built-in User email confirmation dialog, for example -- again, because I won't require email at all in many cases.So for my use-case, am I forced to either build my own User model from the ground up, or to finagle fake email addresses that are unique just to satisfy this constraint?
Am I really in the minority wanting this functionality?
Thanks.
Steve
slgoldberg commentedon Feb 21, 2016
Ah hah -- man, sometimes it's really hard piecing together what's what from a Google search given how active development is on this (though, that's a good thing of course).
Anyway, I think I figured out that in fact you do correctly support this dichotomy of uses in the current implementation of the built-in User model (as of 2016, anyway). I see in the code, all I needed to do was add
"realmRequired": trueto theoptionsobject in my derived user model, e.g.:With
realmRequired: true, email is not required to be unique. Excellent!So that's pretty much just what I needed in my case (I am fine requiring
realm, as I said above, it makes total sense thatrealm+usernamewould replaceemailas the primary-ish key.Thanks a lot -- I'm good to go. Though as usual, maybe there's something I can do to help improve the docs, will look at it again later and update this if so with proposed improvement (or not :-) ).
Steve
pulkitsinghal commentedon Apr 11, 2016
In the sample below, I remove everything from the custom
MyModelwhich extendsUser:Some ideas came from: issue #1137
How can this be helpful? Well what if you're trying to experiment with a multi-tenant setup where
MyModelis actuallyOrgModel? It may help.buzai commentedon Jul 29, 2016
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.
Of course, if you replace the mailbox with a phone number, a lot of places need to change, first of all, you may not need to change the token, but the certification section has to make a lot of changes.
pulkitsinghal commentedon Jul 30, 2016
In my example code in my previous comment, I am not changing the built-in
usermodel, I'm changingMyModelwhich inherited fromusermodel. So no harm done, I hope you agree @buzai? Unless I'm nuking a shared prototype unknowingly? Let me know.buzai commentedon Aug 1, 2016
@pulkitsinghal , I'm not saying you destroy something, I think if you do not use it's own mailbox, then how to generate the user's token it, then you have to write your own method of generating token, there is a lot of built-in methods you can not use the fact, I think if we do so, not as a direct write a model, rather than inherited user. I look at the code inside the user's login and also implements several methods to create a similar, but those methods and mailbox properties coupled together.