Prerequisites
- You need to be on Spree 5.1+, we recommend using spree_starter as a base for your application
- You need to have 2 environment variables set:
KEYGEN_ACCOUNT_IDKEYGEN_LICENSE_KEY
- We support both PostgreSQL and MySQL databases
Environment variables will be provided to you after purchasing the Spree Enterprise Edition license.
Customer User Class
Please follow Authentication documentation to create a new user class. Now we will need to make slight adjustments to the generated user class so it can work in a multi-tenant environment. If you’re using Devise, you will need to remove:validatable module. This module is responsible for validating the user’s email uniqueness. We need to change it to validate it in the scope of the tenant.
Spree Multi-Tenant gem injects SpreeMultiTenant::CustomerUserConcern that handles that instead.
Admin User Class
For our multi-tenant setup we will need a separate Admin user class. Our standard User class will be only used for customer accounts which will be isolated by tenant. Admin user classes will be shared across tenants allowing them to manage multiple tenants from a single admin panel. Let’s create a new model with Devise (unless you already have one):config/initializers/spree.rb:
Installing gems
-
Add the following code to your
Gemfile: -
Install gems:
-
Run generators:
This will copy and run migrations for
spree_enterpriseandspree_multi_tenantgems.

