---
title: "Show parts of a page to the right people"
description: "Show a region only to someone signed in, with a role, in a workspace, on a plan with a feature, or with room left on a quota, with <Gate> and its fallback slot. One component replaces the four boundaries."
canonical_url: "https://nuxt-backend.dev/docs/build/ui/gate"
---
# Show parts of a page to the right people

> Show a region only to someone signed in, with a role, in a workspace, on a plan with a feature, or with room left on a quota, with <Gate> and its fallback slot. One component replaces the four boundaries.

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.

Show the "New strip" button to members whose plan includes illustrated strips, and an upgrade offer to everyone else. `<Gate>` renders its content only when the person passes every check you name, and its `#fallback` slot otherwise. It never shows the content while the checks load, and never shows the fallback before it knows. The function behind the content checks the same rule on the server: the gate decides what a page shows, never what a person may do. Vue and Nuxt have no notion of roles or plans; the package reads them from the session and the billing state, live, and gives each check a server half.

## Gate a region

```vue [app/pages/strips/index.vue]
<script setup lang="ts">
definePageMeta({ auth: true })
</script>

<template>
  <main>
    <h1>Strips</h1>
    <Gate feature="illustrations">
      <NuxtLink to="/strips/new">New strip</NuxtLink>
      <template #fallback>
        <UpgradePrompt feature="illustrations" />
      </template>
    </Gate>
    <!-- No fallback: with no room left, it names the plans that allow more. -->
    <Gate quota="strips">
      <NuxtLink to="/strips/import">Import a strip</NuxtLink>
    </Gate>
  </main>
</template>
```

Every prop you set is a check, and every check must pass, so one fallback answers them all. Give a feature and a quota a gate each when each needs its own offer, as above. Naming any check also asks for a sign-in, so a signed-out visitor gets the fallback.

<table>
<thead>
  <tr>
    <th>
      Prop
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Passes when
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        signed-in
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      A signed-in account that is not banned
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        role
      </code>
    </td>
    
    <td>
      <code>
        string | string[]
      </code>
    </td>
    
    <td>
      The account has one of these app-wide roles, such as <code>
        admin
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        workspace
      </code>
    </td>
    
    <td>
      <code>
        boolean | string | string[]
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
      
      : the session has an active workspace. A role or a list (<code>
        'owner'
      </code>
      
      , <code>
        ['owner', 'admin']
      </code>
      
      ): the person holds one of them there
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        feature
      </code>
    </td>
    
    <td>
      <code>
        string | string[]
      </code>
    </td>
    
    <td>
      The active workspace's plan grants one of these features
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        quota
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The plan has room for <code>
        amount
      </code>
      
       more of this quota
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        amount
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      How many the content needs room for, with <code>
        quota
      </code>
      
      . <code>
        1
      </code>
      
       by default
    </td>
  </tr>
</tbody>
</table>

## Slots

<table>
<thead>
  <tr>
    <th>
      Slot
    </th>
    
    <th>
      Renders
    </th>
    
    <th>
      Receives
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      default
    </td>
    
    <td>
      Every check passed
    </td>
    
    <td>
      <code>
        workspace
      </code>
      
       with <code>
        workspace
      </code>
      
      ; <code>
        limit
      </code>
      
      , <code>
        used
      </code>
      
       and <code>
        remaining
      </code>
      
       with <code>
        quota
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        fallback
      </code>
    </td>
    
    <td>
      A check failed
    </td>
    
    <td>
      With <code>
        quota
      </code>
      
      : the plans that allow more and the link to the first
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        placeholder
      </code>
    </td>
    
    <td>
      The checks are loading, on the server render and until the page has hydrated
    </td>
    
    <td>
      Nothing
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        error
      </code>
    </td>
    
    <td>
      The plan's features or quotas could not be read
    </td>
    
    <td>
      <code>
        { error }
      </code>
      
      , as <code>
        { code, data, message }
      </code>
    </td>
  </tr>
</tbody>
</table>

The server render shows the `placeholder`, never the content, so gated content is not in the HTML a crawler or a slow connection sees first. Without a `fallback`, a failed check renders nothing, except `quota`: it says how many are used of how many, names the plans that allow more, and links to the first. A member who manages no billing reads who to ask instead of a link. Its words are the `quota` [labels](https://nuxt-backend.dev/docs/build/ui/customize/labels#the-groups).

## Enforce the same rule on the server

The gate reads the session and the plan in the browser, where anyone can change what runs. Each check has a server half, and the function behind the content uses it:

<table>
<thead>
  <tr>
    <th>
      <code>
        <Gate>
      </code>
      
       prop
    </th>
    
    <th>
      The function behind it
    </th>
    
    <th>
      The page guard
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        signed-in
      </code>
    </td>
    
    <td>
      Any tier: <code>
        authed
      </code>
      
       and up
    </td>
    
    <td>
      <code>
        definePageMeta({ auth: true })
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        role
      </code>
    </td>
    
    <td>
      <code>
        admin
      </code>
      
       or <code>
        withRole(role)
      </code>
    </td>
    
    <td>
      <code>
        auth: { role }
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        workspace
      </code>
    </td>
    
    <td>
      <code>
        workspace
      </code>
      
      , then <code>
        ctx.workspace.role
      </code>
      
       for a role
    </td>
    
    <td>
      <code>
        auth: { workspace }
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        feature
      </code>
    </td>
    
    <td>
      <code>
        withFeature(key)
      </code>
    </td>
    
    <td>
      <code>
        auth: { feature }
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        quota
      </code>
    </td>
    
    <td>
      <code>
        billing.requireQuota
      </code>
      
      , which refuses with <code>
        quota_exceeded
      </code>
    </td>
    
    <td>
      none: a quota changes while the page is open
    </td>
  </tr>
</tbody>
</table>

[Protect backend functions](https://nuxt-backend.dev/docs/build/auth/access/functions) covers the tiers, and [Protect pages](https://nuxt-backend.dev/docs/build/auth/access/pages) the guard.

## What it guarantees

It renders exactly one slot, so each state is as accessible as what you put in it. Loading is the `placeholder`, or nothing. With `quota`, the packaged refusal is a polite status whose one stop is a real link, and a failed read is an alert. [Accessibility](https://nuxt-backend.dev/docs/build/ui/accessibility) has what a slot of yours keeps.

## What happens when…

<table>
<thead>
  <tr>
    <th>
      Situation
    </th>
    
    <th>
      Result
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      The plan changes while the page is open
    </td>
    
    <td>
      The gate follows at once, in every open tab
    </td>
  </tr>
  
  <tr>
    <td>
      The person signs out
    </td>
    
    <td>
      Every gate shows its fallback
    </td>
  </tr>
  
  <tr>
    <td>
      The features or quotas cannot be read
    </td>
    
    <td>
      The <code>
        error
      </code>
      
       slot, or nothing
    </td>
  </tr>
  
  <tr>
    <td>
      Someone edits the page in the browser to show gated content
    </td>
    
    <td>
      The function behind it refuses: <a href="https://nuxt-backend.dev/docs/reference/backend/errors#feature_required">
        <code>
          feature_required
        </code>
      </a>
      
      , <a href="https://nuxt-backend.dev/docs/reference/backend/errors#quota_exceeded">
        <code>
          quota_exceeded
        </code>
      </a>
      
       or <a href="https://nuxt-backend.dev/docs/reference/backend/errors#forbidden">
        <code>
          forbidden
        </code>
      </a>
    </td>
  </tr>
</tbody>
</table>

## Limits

- **Display only.** Every check needs its server half; the gate alone protects nothing.
- **Built-in workspace roles.** Custom permissions wait for a later release ([Roadmap](https://nuxt-backend.dev/docs/start/roadmap)).

## Test it

```ts [test/new-strip.test.ts]
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { createBackendMock, resetBackendMock } from 'nuxt-backend/test-utils'
import { afterEach, expect, it } from 'vitest'
import StripsPage from '~/pages/strips/index.vue'

afterEach(() => resetBackendMock())

it('offers an upgrade to a plan without the feature', async () => {
  createBackendMock({ user: { name: 'Ada' } })
  const page = await mountSuspended(StripsPage)
  expect(page.find('[data-upgrade]').exists()).toBe(true)
})
```

## Related

- [Protect pages](https://nuxt-backend.dev/docs/build/auth/access/pages): who may open a whole page.
- [Feature gating](https://nuxt-backend.dev/docs/build/billing/subscriptions/feature-gating): features, `<UpgradePrompt>` and `withFeature`.
- [Plan quotas](https://nuxt-backend.dev/docs/build/billing/subscriptions/quotas): quotas in the catalog and `requireQuota`.
- [Show app-wide notices](https://nuxt-backend.dev/docs/build/ui/notices): the other component every layout places.


## Sitemap

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