A SaaS application typically implements a role-based access control system to manage user permissions and restrict access to specific features or content.
For instance, free-tier users may only have access to basic functionalities and limited content, while paid users can unlock premium features and exclusive resources.
Additionally, administrators are granted elevated privileges, enabling them to oversee and manage the entire system, including user accounts, content, and application settings.
This tiered, role-based access structure ensures a secure and organized user experience.
Extending the User table
In order to implement such system using Auth.js, we must expand the default User
table to include information about the user's role.
Go to prisma/schema.prisma
and add a role
column like this:
1model User {
2 id String @id @default(cuid())
3 name String?
4 email String? @unique
5 emailVerified DateTime?
6 image String?
7 role String? @default("free user") // Add a new "role" column
8 accounts Account[]
9 sessions Session[]
10
11 createdAt DateTime @default(now())
12 updatedAt DateTime @updatedAt
13}
Apply the new schema by running the following command:
1npx prisma migrate dev