Building a full-fledged multi-tenant application can be very challenging. Besides having a flexible sign-up and sign-in system, you also need to implement several other essential pieces:
- Creating and managing tenants
- User invitation flow
- Managing roles and permissions
- Enforcing data segregation and access control throughout the entire application
It sounds like lots of work, and it indeed is. You may have done this multiple times if you're a veteran SaaS developer.
: the full-stack framework
: the ORM that we use to talk to the database
. Verify the basic sign-up/sign-in flow is working. Also, in StackAuth's management console, enable "Client-Side Team Creation" and "Automatic Team Creation" options in the "Team Settings" section.
Although StackAuth made it effortless to add "teams" feature into an app, it's up to you to determine how to use the user and team information to control data access. We'll see how to connect it with Prisma/ZenStack to achieve proper authorization.
Setting up the database
Our user and team data are stored on StackAuth's side. We need to store the todo lists and items in our own database. In this section, we'll set up Prisma and ZenStack and create the database schema.
Let's start with installing the necessary packages:
npm install --save-dev prisma zenstack
npm install @prisma/client @zenstackhq/runtime
Then we can create the database schema. Please note that we're creating a schema.zmodel file (as a replacement of "schema.prisma"). The (RSC) and
The components that manage Todo items are not shown for brevity, but the ideas are similar. You can find the fully completed code for teams. Although not covered in this post, with some tweaking, you should be able to leverage it to define access policies. That way, you can manage permissions with StackAuth's dashboard and have ZenStack enforce them at runtime.
SOCIAL SHARE CARD GENERATOR