joas8211 / payload-tenancy

Multi-tenancy plugin for Payload CMS
MIT License
149 stars 10 forks source link

User with same email on different tenants not possible #23

Open silveltman opened 1 year ago

silveltman commented 1 year ago

When a user is created in a specific tenant, it cannot be created with the same email on another tenant. For backend users (user editing via the payload admin panel) this is not a problem, but it is a problem for front-end users (customers that log into an ecommerce site).

As I see it we can fix this in a couple of ways:

  1. Allow for multiple users with the same email, while they have a different ID (seems vulnerable and don't think this is possible with payload)
  2. Have the tenancy plugin add the tenant slug before of after the email, so test@gmail becomes mytenant-test@gmail.com.
  3. Have the tenancy plugin create a sepereate auth collection for each tenant. I think this is the best option of the 3, so let me elaborate:

How I see option 3 would start by adding a config option to this plugin which allows us to choose which auth collection should be used to set the tenant and filter the docs in each collection. So:

plugins: [tenancy({ authCollection: "users" })],

Then we can create a seperate auth collection in payload for the frontend, which we call customers in this case.

This plugin would then need to create a collection named mytenant-customers and route the api request to the correct ones.

Pro: seems like easiest of the 3 to make Con: Not in line with the nature of this plugin, which is filtering the same collection, not creating new ones

Would love to hear what you think!

joas8211 commented 1 year ago

This is definitely an interesting problem. Some thoughts: