feathers js multi tenant example
This project uses Feathers. An open source web framework for building modern real-time applications.
You can create multi tenancy by
- Adding a tenant service
- Associating each user to a tenant (src/models/users.model.js)
- When ever you create a new service/model, for example a blog post, make sure to associate it with a tenant (src/models/blog-post.model.js)
- Create a hook that takes the tenantId from user and add it to the model (src/hooks/add-tenant-id-to-entities.js)
- Create another hook that always appends tenantId to the query parameter (src/hooks/restrict-entries-to-a-tenant.js)
Getting up and running is as easy as 1, 2, 3.
-
Install your dependencies
cd path/to/feathers-multi-tenant-example npm install
-
Start your app, so sqlite database is created
npm start
-
Kill npm process
-
Create superadmin
node create_super_admin.js
-
Start your app
npm start
Run the attached postman collection in order to see multi tenancy in action
Feathers has a powerful command line interface. Here are a few things it can do:
$ npm install -g @feathersjs/cli # Install Feathers CLI
$ feathers generate service # Generate a new Service
$ feathers generate hook # Generate a new Hook
$ feathers help # Show all commands
For more information on all the things you can do with Feathers visit docs.feathersjs.com.