Adding a Role

To add a role that's available for users, the accounts.roles.add() method can be utilized:


import joystick, { accounts } from '@joystick.js/node';{
}).then(() => {

Above, we tap into the .then() callback that's triggered internally by after our server starts up. Inside, we call to accounts.roles.add('manager') to create the manager role in our database. Keep in mind: this only creates the role in our database but does not grant the role to any users. Roles must be granted on a user-by-user basis.

The purpose of the above .add() method is limited. It's best used in situations where roles need to be available for a feature like an admin UI (where an administrator can select roles to grant to a user) before they're actually granted to users.

API Reference


Function API

accounts.roles.add(role: string) => void;


  • role string Required

    A string defining the name of the role to add.

On This Page