Building a full-fledged multi-tenant application can be very challenging.
Better-auth is an emerging open-source TypeScript authentication framework that offers a comprehensive set of features and great extensibility.
While better-auth solves the problem of determining a user's identity and roles, ZenStack continues from there and uses such information to control what actions the user can perform on a piece of data.
ZenStack is built above Prisma ORM and extends Prisma's power with flexible access control and automatic CRUD API.
The essential weapons we'll use to build the app are: Next.js, Better-Auth, Prisma, ZenStack, and TanStack Query.
We can manipulate the database from the frontend through the generated hooks and automatic API. However, the APIs are open to all without any protection.
The biggest value ZenStack adds above Prisma is access control, which can be implemented directly inside the schema.
In our context, we'll use better-auth to retrieve the current user's identity, active organization, and role in the organization and use this information as the "user context" when creating the enhanced PrismaClient.
With the CRUD APIs secured and frontend hooks generated, implementing the UI for managing TodoLists becomes very straightforward.
This post demonstrated how the work can be significantly simplified and streamlined by combining better-auth and ZenStack.