# Add a permission of your own and check it

Define a permission your app checks, such as exporting reports, give it to workspace roles in the console, and check it in your app and on your server.

BuildBase enforces its own permissions, such as who may invite a member or
manage billing. Your app has its own: may this member export a report, publish
a document, see the audit page. You define those in the console beside
BuildBase's, give them to workspace roles, and your app and your server ask the
same question. This guide adds `app:reports:export` for Acme Analytics and
gives it to editors.

> **Note:**
  Workspaces in Platform mode (permissions are not used in Personal mode; see
  [mode and limits](/workspaces/workspace-settings)), a console role that can
  update workspace settings, and room in your plan for one more permission.

## 1. Open Permissions

[Open Workspace configuration in the console](https://console.buildbase.app/dashboard/admin/workspaces/settings)

In the left rail choose **Users**, then **Settings** under **Workspaces**, and
scroll to **Permissions**. Under **Your app's permissions**, press **Add
permission**.

![The Permissions section of Workspace configuration: Your app's permissions, with the Add permission button highlighted as step 1](/images/permissions/app-permissions/add.webp)

## 2. Name it

Fill the three fields of the new row:

- **The key**, what your code checks: lowercase letters, digits and `. : _ -`, up to 64 characters, such as `app:reports:export`. Keys starting with `workspace:`, `buildbase:`, `system:` or `org:` are BuildBase's.
- **The label**, what your team reads, such as `Export reports`.
- **A group**, optional, such as `Reports`, to file it under in the matrix.

![A new row under Your app's permissions: the key app:reports:export, the label Export reports and the group Reports, highlighted together as step 2, and Remove](/images/permissions/app-permissions/fields.webp)

## 3. Give it to roles

The permission appears in the matrix below, under its group. Switch it on for
each role that may use it. **Admin** holds every permission, yours included,
so its switch is locked on.

![The matrix row Export reports under Reports: admin locked on, and the editor switch turned on and highlighted as step 3](/images/permissions/app-permissions/grant.webp)

## 4. Save

Press **Save permissions**. It saves the new permission and who has it in one
go.

![The Save permissions button below the matrix, highlighted as step 4](/images/permissions/app-permissions/save.webp)

## 5. See it in the change history

**Change history**, at the bottom of the page, shows the permission added and
the role given it.

![Change history: the newest entry by Alex Morgan, highlighted as step 5, with Permission added: app:reports:export and Given to editor: app:reports:export](/images/permissions/app-permissions/history.webp)

## 6. Check it in your app and on your server

In your app, `usePermissions()` answers for the person in their current
workspace:

```tsx
import { usePermissions } from '@buildbase/sdk/react';

export function ReportActions() {
  const { can } = usePermissions();
  return can('app:reports:export') ? <ExportButton /> : null;
}
```

On your server, ask BuildBase rather than trusting the browser:

```ts
const res = await fetch(
  `${serverUrl}/api/v1/public/workspaces/${workspaceId}/permissions/me`,
  { headers: { 'x-session-id': sessionId } }
);
const { data } = await res.json(); // { role, isOwner, permissions: string[] }
if (!data.permissions.includes('app:reports:export')) return forbidden();
```

A workspace can change what each role may do for itself. On the permissions
screen of the SDK's settings dialog (`openWorkspaceSettings('permissions')`),
the workspace's creator ticks a permission for a role and presses **Save
Permissions**; over the API, `PATCH /api/v1/public/workspaces/:workspaceId/permissions`
takes the same change from any member with `workspace:settings:edit`. That
workspace's answer then comes from its own choice; every other workspace keeps
yours. The screen appears only once your organization has a permission of its
own, such as the one this guide adds.

![The SDK's Permissions screen for Northwind Traders: Export reports, app:reports:export, on for Admin (locked) and Editor and off for Viewer, and the Save Permissions button highlighted as step 6](/images/permissions/app-permissions/sdk-override.webp)

## Check it works

Sign in to your app as an editor: the export button shows. Sign in as a viewer:
it does not. `permissions/me` gives each of them the same answer.

## Things to watch out for

- **A key cannot be renamed.** Every grant points at it by name. Remove the permission and add the new key.
- **Removing a permission removes its grants everywhere**, workspace overrides included.
- **At most 100 permissions, whatever the plan**, and your plan may allow fewer: the counter beside **Add permission** shows where you are.
- **Nobody below admin grants more than they hold.** A workspace member cannot change their own role's permissions or give a role something they lack.

## Next Steps

- [Permissions and roles](/permissions/overview) - the roles, the matrix and how a workspace overrides it.
- [Checking permissions](/permissions/checking-permissions) - every constant and check.
- [Mode and limits](/workspaces/workspace-settings) - the roles a member can hold.
