The Roles service provides methods for managing roles and permissions.
Overview
import { SnackBaseClient } from "@snackbase/sdk";
const client = new SnackBaseClient({
baseUrl: "https://api.example.com",
});
// Access the roles service
const roles = client.roles;
List Roles
const result = await client.roles.list();
Get a Role
const role = await client.roles.get("role-id");
Create a Role
const role = await client.roles.create({
name: "editor",
description: "Can create and edit content",
permissions: [
{
collectionId: "posts",
actions: ["create", "read", "update"],
},
],
});
Update a Role
const updated = await client.roles.update("role-id", {
name: "Senior Editor",
});
Delete a Role
await client.roles.delete("role-id");
Deleting a role removes it from all users who have it. Ensure users have
alternative roles before deleting.
Assign Role to User
await client.roles.assignToUser("role-id", "user-id");
Remove Role from User
await client.roles.removeFromUser("role-id", "user-id");
Next Steps