
In this example, each user has one of two roles: admin or staff.
RBAC Example 1: Use Get Record
Now, let’s set up an API endpoint that GETs all users but only if the user trying to call the endpoint has a role of admin. Take note of the endpoint below, user authentication is required. Additionally, take note of the Function Stack:- Get Record from user: This will use the authToken to find the user’s ID and look up their information.
- Precondition: This will enforce that the user’s role is equal to admin. If it is not, then it will throw and error and stop the endpoint.
- Query all records from user: This will only be performed if the user’s role is an admin by passing the precondition.

In this example, the API endpoint requires an authenticated user. Then the Function Stack is set up to perform only if the user's role is equal to admin.

In this example, we are getting the record of the user based on their authenticated ID.

Click on the pencil icon to open the Expression Builder and set the conditions for the precondition. Additionally, set your error type and message if the conditions are not met.

In this example, the requester.role must be equal to admin in order to pass the precondition.
RBAC Example 2: Use Extras
Extras allow you to store data within the authentication token, which you can access and use on authenticated API endpoints. First, you must set up the sign-up & login to include the user’s role at the time of authentication. In this example, we will use the login endpoint to pass the user’s role into extras of the auth token at the time of authentication.
In this example, we are passing the user's role into the authToken at the time of login by utilizing extras.

In this example, we can use the extras of the authenticated user to access the user's role and set the precondition equal to admin.

Set extras.role (as defined in the creation of the authentication token) equal to admin.