Skip to main content

If you are using our backend SDK that is lesser than the following versions, please visit the older documentation link here.

Creating a new role#

When using SuperTokens, roles and permissions are simple strings that can be assigned to users and verified on your backend and frontend.

When creating new roles you can choose to add 0 or multiple permissions to the role.

important

Roles must be ceated before they can be assigned to users

tip

Roles can also be created from the user management dashboard. To know more about how to manage your user roles and permissions from user management dashboard see this page.

import UserRoles from "supertokens-node/recipe/userroles";

async function createRole() {
/**
* You can choose to give multiple or no permissions when creating a role
* createNewRoleOrAddPermissions("user", []) - No permissions
* createNewRoleOrAddPermissions("user", ["read", "write"]) - Multiple permissions
*/
const response = await UserRoles.createNewRoleOrAddPermissions("user", ["read"]);

if (response.createdNewRole === false) {
// The role already exists
}
}
Multi Tenancy

In a multi tenant setup, roles and permissions are shared across all tenants. This means that you can create a role and add permissions to it once, and reuse that role across any tenant in your app.

Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI