To revoke a role from an existing user, the accounts.roles.revoke()
method can be utilized.
Example Usage
index.server.js
import joystick, { accounts } from '@joystick.js/node';
joystick.app({
accounts: {
events: {
on_logout: (user = {}) => {
accounts.roles.revoke(user?._id, 'active_account');
},
},
},
});
Above, we tap into the account event hook for the on_logout()
event to revoke the temporary role active_account
from a user. When a role is revoked, it is removed from the roles
array on the user’s document/row in the database.
API
Definition
accounts.roles.revoke(user_id: string, role: string) => void;
Parameters
- user_id string required
-
A user ID from your
users
collection/table in the database (e.g.,user._id
for MongoDB oruser.user_id
for PostgreSQL). - role string required
- A string defining the name of the role to revoke from the specified user.