sourcefuse / loopback4-starter

Loopback 4 starter application. Multi-tenant architecture supported. Authentication, Authorization, Soft deletes, environment vars, Audit logs, included.
MIT License
158 stars 59 forks source link

approach to identify data in each tenant #95

Closed sambathsrey closed 2 years ago

sambathsrey commented 2 years ago

Thank you for providing this awesome boilerplate! How can I identify data that belong to the specific tenant? How many approaches can I implement? As my research I have seen that I need to have an identifier column "tenant_id" for every tables. If so, how should I use that "tenant_id" column? Should it be a foreign key or just a normal column?

akshatdubeysf commented 2 years ago

You can refer to this example project, it uses a user_tenant_id every where that refers to the ids in the user - tenant relation table.

akshatdubeysf commented 2 years ago

If you don't need the user, just the tenant, you can store the tenant_id in each table that refers the id in the tenants table, as long as both tables are in the same db.

sambathsrey commented 2 years ago

Thank you.