> ## Documentation Index
> Fetch the complete documentation index at: https://docs.snackbase.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Roles Service

> Manage roles and permissions for access control

The Roles service provides methods for managing roles and permissions.

## Overview

```ts theme={null}
import { SnackBaseClient } from "@snackbase/sdk";

const client = new SnackBaseClient({
  baseUrl: "https://api.example.com",
});

// Access the roles service
const roles = client.roles;
```

## List Roles

```ts theme={null}
const result = await client.roles.list();
```

## Get a Role

```ts theme={null}
const role = await client.roles.get("role-id");
```

## Create a Role

```ts theme={null}
const role = await client.roles.create({
  name: "editor",
  description: "Can create and edit content",
  permissions: [
    {
      collectionId: "posts",
      actions: ["create", "read", "update"],
    },
  ],
});
```

## Update a Role

```ts theme={null}
const updated = await client.roles.update("role-id", {
  name: "Senior Editor",
});
```

## Delete a Role

```ts theme={null}
await client.roles.delete("role-id");
```

<Warning>
  Deleting a role removes it from all users who have it. Ensure users have
  alternative roles before deleting.
</Warning>

## Assign Role to User

```ts theme={null}
await client.roles.assignToUser("role-id", "user-id");
```

## Remove Role from User

```ts theme={null}
await client.roles.removeFromUser("role-id", "user-id");
```

## Next Steps

* **[Groups Service](/sdk/js/services/groups)** - Manage user groups
* **[Collection Rules](/sdk/js/services/collections)** - Fine-grained access control
* **[Permissions](/permissions)** - Understand the permission system
