@prisma-multi-tenant/redwood
TypeScript icon, indicating that this package has built-in type declarations

2.4.2 • Public • Published

Redwood plugin for Prisma-multi-tenant 🧭

Version Documentation Maintenance License: MIT Twitter: Errorname_

🧭 Add multi-tenancy to your Redwood application

Installation

yarn global add prisma-multi-tenant # CLI for tenant management
yarn add @prisma-multi-tenant/redwood # Redwood plugin

cp api/
prisma-multi-tenant init # Init multi-tenancy in your Redwood project

Usage

⚠️ First, make sure you followed the Prisma-multi-tenant Getting Started Guide. ⚠️

First, replace the code in api/src/lib/db.js with the following:

import { MultiTenant, fromContext } from '@prisma-multi-tenant/redwood'

export const multiTenant = new MultiTenant()
export const db = fromContext()

Then, update the code in api/src/functions/graphql.js:

import { multiTenant } from 'src/lib/db'

export const handler = createGraphQLHandler({
  schema: makeMergedSchema({
    schemas,
    services: makeServices({ services }),
  }),
  context: async ({ event }) => ({
    // The name can come from anywhere (headers, token, ...)
    db: await multiTenant
      .get('dev') // or 'my_tenant_A' or anything
      .catch(console.error),
  }),
})

Finally, restart the server:

yarn redwood dev

Example

Check out an example application using Redwood and the multi-tenant plugin here.

Documentation

Read more on how prisma-multi-tenant can help you achieve multi-tenancy for your apps:

Author

👤 Thibaud Courtoison

🤝 Contributors

Contributions, issues, and feature requests are welcome! 🙌

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2020 Thibaud Courtoison.

This project is MIT licensed.

Package Sidebar

Install

npm i @prisma-multi-tenant/redwood

Weekly Downloads

0

Version

2.4.2

License

MIT

Unpacked Size

6.08 kB

Total Files

4

Last publish

Collaborators

  • errorname