Permissions are a way to control what each user can do and access within your application.Documentation Index
Fetch the complete documentation index at: https://stackauth-e0affa27-chore-move-mcp-to-a-sep-app.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Permission Types
Stack supports two types of permissions:- Team Permissions: Control what a user can do within a specific team
- User Permissions: Control what a user can do globally, across the entire project
Team Permissions
Team permissions control what a user can do within each team. You can create and assign permissions to team members from the Stack dashboard. These permissions could include actions likecreate_post or read_secret_info, or roles like admin or moderator. Within your app, you can verify if a user has a specific permission within a team.
Permissions can be nested to create a hierarchical structure. For example, an admin permission can include both moderator and user permissions. We provide tools to help you verify whether a user has a permission directly or indirectly.
Creating a Permission
To create a new permission, navigate to theTeam Permissions section of the Stack dashboard. You can select the permissions that the new permission will contain. Any permissions included within these selected permissions will also be recursively included.
System Permissions
Stack comes with a few predefined team permissions known as system permissions. These permissions start with a dollar sign ($). While you can assign these permissions to members or include them within other permissions, you cannot modify them as they are integral to the Stack backend system.
Checking if a User has a Permission
To check whether a user has a specific permission, use thegetPermission method or the usePermission hook on the User object. This returns the Permission object if the user has it; otherwise, it returns null. Always perform permission checks on the server side for business logic, as client-side checks can be bypassed. Here’s an example:
- Client Component
- Server Component
Check user permission on the client
Listing All Permissions of a User
To get a list of all permissions a user has, use thelistPermissions method or the usePermissions hook on the User object. This method retrieves both direct and indirect permissions. Here is an example:
- Client Component
- Server Component
List user permissions on the client
Granting a Permission to a User
To grant a permission to a user, use thegrantPermission method on the ServerUser. Here’s an example:
Revoking a Permission from a User
To revoke a permission from a user, use therevokePermission method on the ServerUser. Here’s an example:
Project Permissions
Project permissions are global permissions that apply to a user across the entire project, regardless of team context. These permissions are useful for handling things like premium plan subscriptions or global admin access.Creating a Project Permission
To create a new project permission, navigate to theProject Permissions section of the Stack dashboard. Similar to team permissions, you can select other permissions that the new permission will contain, creating a hierarchical structure.
Checking if a User has a Project Permission
To check whether a user has a specific project permission, use thegetPermission method or the usePermission hook. Here’s an example:
- Client Component
- Server Component
Check user permission on the client
Listing All Project Permissions
To get a list of all global permissions a user has, use thelistPermissions method or the usePermissions hook:
- Client Component
- Server Component
List global permissions on the client
Granting a Project Permission
To grant a global permission to a user, use thegrantPermission method:
Revoking a Project Permission
To revoke a global permission from a user, use therevokePermission method: