---
title: "Give people roles"
description: "Two kinds of role decide what a person may do: an app-wide role (user, admin or one of yours) and a built-in role in each workspace (owner, admin, member). How to give each, and how pages and functions check them."
canonical_url: "https://nuxt-backend.dev/docs/build/auth/access/roles"
---
# Give people roles

> Two kinds of role decide what a person may do: an app-wide role (user, admin or one of yours) and a built-in role in each workspace (owner, admin, member). How to give each, and how pages and functions check them.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/authorization.ts)

Two kinds of role decide what a person may do. An **app-wide role** holds everywhere in your app: `user` for everyone, `admin` for the people who run it, and names of your own such as `editor`. A **workspace role** holds inside one workspace: `owner`, `admin` or `member`. Better Auth's admin plugin keeps the first, and its organization plugin the second. The package puts both on the session token, checks them in your pages and functions, and reads them fresh where a stale answer would matter.

## App-wide roles

Every account starts as `user`. The role decides what the app lets a person do anywhere:

<table>
<thead>
  <tr>
    <th>
      Role
    </th>
    
    <th>
      Gives
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        user
      </code>
    </td>
    
    <td>
      The app, as every signed-in person sees it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        admin
      </code>
    </td>
    
    <td>
      The <a href="https://nuxt-backend.dev/docs/build/auth/admin">
        admin console
      </a>
      
       at <code>
        /admin
      </code>
      
      , the <code>
        admin
      </code>
      
       function tier, and your own pages guarded by <code>
        role: 'admin'
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      A name of yours, such as <code>
        editor
      </code>
    </td>
    
    <td>
      What your own pages and functions grant it, through <code>
        withRole('editor')
      </code>
      
       and <code>
        role: 'editor'
      </code>
      
      .
    </td>
  </tr>
</tbody>
</table>

### Make the first administrator

A new deployment has none. Sign in once with your own address, then run `doctor --fix` and enter that address when it asks:

```bash
npx nuxt-backend doctor --fix
```

In CI or a script, call the scaffold's internal `setUserRole`, which no browser can reach:

```bash
npx convex run functions:setUserRole '{"email":"you@example.com","role":"admin"}'
```

Both record the change on the [activity trail](https://nuxt-backend.dev/docs/build/auth/admin/audit-log), as the app's.

### Give a role of your own

Administrators set roles from the Users tab of the admin console. List the roles it offers with `<AdminUsers>`'s `roles` prop, on your own admin page:

```vue [app/pages/admin/people.vue]
<script setup lang="ts">
definePageMeta({ auth: { role: 'admin' } })
</script>

<template>
  <AdminUsers :roles="['user', 'editor', 'admin']" />
</template>
```

A role is a name: there are no permission lists to define. Then check it wherever it grants something:

```ts [backend/strips.ts]
import { v } from 'convex/values'
import { withRole } from './functions'

export const feature = withRole('editor').mutation({
  args: { stripId: v.id('strips') },
  handler: async (ctx, { stripId }) => {
    await ctx.db.patch('strips', stripId, { featured: true })
  },
})
```

## Workspace roles

Every member of a workspace has one built-in role in it. The person who creates a workspace is its `owner`, and the people they invite join as `member` or `admin`:

<table>
<thead>
  <tr>
    <th>
      Role
    </th>
    
    <th>
      May
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        owner
      </code>
    </td>
    
    <td>
      Everything an admin may, and keep the workspace: Better Auth refuses to leave a workspace without an owner.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        admin
      </code>
    </td>
    
    <td>
      Invite people, cancel invitations, remove members and change their roles. Manage the workspace's plan and credits.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        member
      </code>
    </td>
    
    <td>
      Work in the workspace, and see its members and usage.
    </td>
  </tr>
</tbody>
</table>

[Manage members](https://nuxt-backend.dev/docs/build/auth/workspaces/members) changes them. Roles an owner defines, and billing as a permission inside a role, wait for a later release ([Roadmap](https://nuxt-backend.dev/docs/start/roadmap#service-app-features)).

## Check a role

<table>
<thead>
  <tr>
    <th>
      Where
    </th>
    
    <th>
      App-wide role
    </th>
    
    <th>
      Workspace role
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      A page
    </td>
    
    <td>
      <code>
        definePageMeta({ auth: { role: 'admin' } })
      </code>
    </td>
    
    <td>
      <code>
        workspace: 'owner'
      </code>
      
       in the same rules (<a href="https://nuxt-backend.dev/docs/build/auth/access/pages">
        Protect pages
      </a>
      
      )
    </td>
  </tr>
  
  <tr>
    <td>
      A part of a page
    </td>
    
    <td>
      <code>
        <Gate role="editor">
      </code>
    </td>
    
    <td>
      <code>
        <Gate workspace="owner">
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      A function
    </td>
    
    <td>
      the <code>
        admin
      </code>
      
       tier, or <code>
        withRole('editor')
      </code>
    </td>
    
    <td>
      the <code>
        workspace
      </code>
      
       tier, then <code>
        ctx.workspace.role
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Your own markup
    </td>
    
    <td>
      <code>
        useAuth().hasRole('editor')
      </code>
      
      , or <code>
        useAuth().role
      </code>
    </td>
    
    <td>
      <code>
        useWorkspace().role
      </code>
    </td>
  </tr>
</tbody>
</table>

`<Gate>` and page rules decide what the screen shows. The function checks are the ones that protect data, so every function a page calls keeps its tier ([Protect backend functions](https://nuxt-backend.dev/docs/build/auth/access/functions)).

## How fresh a role is

The app-wide role rides on the session token, so a check costs no read. A token can lag a change by up to fifteen minutes, its lifetime. Where that matters, the package reads the account instead:

- The `admin` tier reads the role fresh on every call, so a demoted administrator is refused at once.
- Writes of `authed` and `withRole` read the account fresh, so a ban lands on the next write.
- A workspace role is always read fresh from the member table.

A role you give in the console reaches the person's own token at their next refresh. Their pages catch up then, and their calls are checked right away.

## Related

- [Protect backend functions](https://nuxt-backend.dev/docs/build/auth/access/functions): the tiers that check roles for you.
- [Protect pages and routes](https://nuxt-backend.dev/docs/build/auth/access/pages): `role` and `workspace` rules on a page.
- [Run the admin console](https://nuxt-backend.dev/docs/build/auth/admin): setting roles from `/admin`.
- [Manage members](https://nuxt-backend.dev/docs/build/auth/workspaces/members): workspace roles, changed.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
