Permission Types
Hexclave supports two types of permissions:- Team Permissions: Control what a user can do within a specific team
- Project Permissions: Control what a user can do globally, across the entire project
Dashboard
The RBAC app adds two dashboard pages:- Project Permissions - Global permissions that apply outside of a team context. The dashboard page defines the permissions and their hierarchy.
- Team Permissions - Permissions scoped to a team. The dashboard page defines the permissions and their hierarchy, and team-member assignment happens from the Teams app.
Permission table
Both pages use the same permission table:- ID - The permission ID used in SDK calls, such as
access_admin_dashboardorteam:billing:manage. - Description - Optional human-readable context for the permission.
- Contained Permissions - Directly contained permissions, shown as badges. This column intentionally shows only direct children, not the full recursive expansion.
- Actions - Edit and delete actions for custom permissions.
Creating a permission
Click Create Permission from either RBAC page. The dialog contains:- ID - Required, unique across project and team permission definitions. IDs may contain lowercase letters, numbers,
_, and:only. - Description - Optional text shown in the dashboard table.
- Contained Permission IDs - A checklist of permissions of the same type. For example, a team permission can contain other team permissions, and a project permission can contain other project permissions.
admin contains moderator, and moderator contains read, then a user with admin also has read.
Editing a permission
Use the row action menu and choose Edit. The edit dialog keeps the same fields, with one important difference: ID is disabled. To rename a permission, create a new permission and migrate your checks/assignments. The contained-permissions checklist shows inherited permissions with afrom <permission-id> note, so you can tell whether a permission is selected directly or included through another selected permission.
Deleting a permission
Use the row action menu and choose Delete. Deleting is destructive and requires confirming:System permissions
Hexclave comes with predefined team permissions known as system permissions. These IDs start with$.
System permissions:
- Can be assigned to members
- Can be included inside custom permissions
- Cannot be edited or deleted from the dashboard
Assigning team permissions
Team permission definitions are created in RBAC -> Team Permissions, but assignments happen from the Teams app:- Open Teams.
- Select a team.
- Open the members table.
- Use the row action menu for a member and choose Edit permissions.
Team Permissions
Team permissions control what a user can do within each team. You can create and assign permissions to team members from the Hexclave 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 RBAC -> Team Permissions in the Hexclave dashboard. Click Create Permission, set the permission ID, optionally add a description, and choose any contained permissions. Any permissions included within these selected permissions will also be recursively included.System Permissions
Hexclave 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 Hexclave backend system.
Checking if a User has a Permission
To check whether a user has a specific permission within a team, usehasPermission, getPermission, or the usePermission hook on the User object. getPermission 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
app/api/team-settings/route.ts
Listing All Permissions of a User
To get a list of all permissions a user has in a team, use thelistPermissions method or the usePermissions hook on the User object. By default, the list includes direct and indirect permissions. Pass { recursive: false } if you only want direct assignments. 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 RBAC -> Project Permissions in the Hexclave dashboard. Similar to team permissions, you can set an ID, add a description, and select other project permissions that the new permission contains.Checking if a User has a Project Permission
To check whether a user has a specific project permission, usehasPermission, getPermission, or the usePermission hook. Here’s an example:
- Client Component
- Server Component
Check user permission on the client
app/admin/page.tsx
Listing All Project Permissions
To get a list of all global permissions a user has, use thelistPermissions method or the usePermissions hook. Pass { recursive: false } if you only want direct grants:
- Client Component
- Server Component
List global permissions on the client
{ recursive: false }:
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:
Direct vs. inherited permissions
A permission can be present in two ways:- Direct - The user was explicitly granted that permission.
- Inherited - The user was granted a permission that contains it, directly or recursively.
hasPermission and getPermission, Hexclave resolves contained permissions recursively so roles work as expected.