Auth unique email #3560
Replies: 6 comments 9 replies
-
Hey @dylankuipers! I believe that the email being a unique field is actually the best thing to do overall, because when you log in, you need to be able to find the correct document for that email which contains the password. If you allow multiple users with the same email, now you can't identify which website's user account to actually log in as. In my opinion, to allow that kind of behavior you should create a custom authentication strategy that uses both {
"email": "[email protected]",
"website": "website1.com",
"password": "password"
} Forcing |
Beta Was this translation helpful? Give feedback.
-
Thanks for your response @ChrisGV04, If you're using the tenancy plugin it automatically creates a custom ID for each of your tenants that is also displayed in the user collection. I would use that to determine which site someone is trying to log in to. Although, I am unable to do this as the email field is forced unique. (Which also pretty much makes the plugin useless as people wouldn't be able to make accounts on two different websites of yours) The only way to go around this is to make a new instance of Payload for each of your websites, but this costs money and makes things more complicated. As now you have to manage multiple instances rather than just one. I realised this isn't a bug after posting so my bad about that. And while I do agree with you that I could make a custom authentication strategy, I can't really do that. As the plugin forces one of the collections to be |
Beta Was this translation helpful? Give feedback.
-
I would think that something like the following would be possible:
I would expect this to be possible based on the nature of payload OR if not possible a TS error would be nice. Not a bug though indeed. |
Beta Was this translation helpful? Give feedback.
-
The right way to do this would be to have a relationship field in your users collection with relationTo sites and have your access control be updated to accomodate it that way. If you need to have a I'm going to convert this to a discussion unless we're overlooking something that is an actual bug to solve. Please feel free to continue discussion. |
Beta Was this translation helpful? Give feedback.
-
I see even more benefits of being able to disable email being unique, that have nothing to do with the tenancy plugin. It would allow us to create guest users with only an email. For this to work we would also need to be able to set password to not required. This would allow us to manually create users/customers with the details we have about them (maybe address etc) without the customer having to create an account. Also, for ecommerce this would allow us to create a customer doc in which we store the customers cart. How we currently do this is by creating a random guest account with a random email and password en behind the scene change the email/password when the user "creates an account" while still being logged in the guest account. If there is a better alternative, please let me know! |
Beta Was this translation helpful? Give feedback.
-
I've got an update that this is not as easy as I had thought. I tried to do this on my own and ran into some trouble that makes it not currently feasible. I thought we were using the Not only is that written into the register function, the built-in auth needs to have unique email fields or we would need to disable the workflow for forgot password / reset password or change it to somehow work with more than one user record. I think for anyone needing this you'll need to create a custom auth strategy or make it into a Payload plugin. Alternatively if we can navigate the issues involved here I'd entertain merging in a PR. There might be another workaround solution to this like adding a user scoping config option or function that can act as a filter on the user results that then a What do we think? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Link to reproduction
Not relevant
To Reproduce
User collection with "auth: true" and have multiple projects in the same Payload instance.
Describe the Bug
Hi, so I am using a plugin for Payload to have multiple projects in one Payload instance. I use the tenancy plugin for this (1). With this plugin you can have the user's accounts for each project in the same collection, but with a different tenant ID.
I have noticed that while using this plugin, it is impossible to have an account with the same email. Imagine you have two projects and they both have their own website. Right now if you were to make an account on both websites with the same email it is impossible to do. This is because payload forces the email to be unique while using "auth: true" in the collection. As this forces an email and password field.
I have tried to overwrite the email field and set the unique value to false. Though I haven't been successful. I would like to make a custom check myself to check whether the email is unique per tenant ID (from the tenant plugin). Although, I am unable to create this check since payload forces the email field to be unique while using "auth: true". And as far as I know it is impossible to overwrite. It would be ideal if there is a way to turn the unique email field off or if I were to be able to overwrite it.
We have tried reporting this issue to the plugin creator (2), without success, we decided to make an issue for payload instead.
(1) Multi tenant plugin: https://github.com/joas8211/payload-tenancy
(2) Issue at plugin: joas8211/payload-tenancy#23
Payload Version
1.15.6
Beta Was this translation helpful? Give feedback.
All reactions