Skip to main content

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

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    }}