---
title: "Composable conventions"
description: "The shape every nuxt-backend composable follows: an options object, refs you can destructure, isLoading, isPending and a typed error, reads that never throw and actions that reject."
canonical_url: "https://nuxt-backend.dev/docs/reference/nuxt/conventions"
---
# Composable conventions

> The shape every nuxt-backend composable follows: an options object, refs you can destructure, isLoading, isPending and a typed error, reads that never throw and actions that reject.

Version: nuxt-backend 0.6.x · Tab: Reference · Kind: reference · 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.

The package's composables are shaped like [VueUse](https://vueuse.org)'s, so you learn the shape once and every composable reads the same. This page is that shape: how you call one, what it returns, and when it rejects. [Composables](https://nuxt-backend.dev/docs/reference/nuxt/composables) lists each one's signature.

## Calling one

```ts
const delivery = useEmailStatus({ emailId })                          // options only
const { results } = useSearch(api.search.searchMessages, { term })     // the query it reads, then options
```

- **Options come in one object**, typed `Use<Name>Options`. A composable that reads a query you wrote takes that query first, the way `useQuery` does, and its options second. `useAiStream` takes your stream's `{ start, body }` pair first the same way. A composable about one thing takes that thing first: `useFlag(key)`, `useLabels(group)`, `useBackendPagePath(page)`, `useJob(jobId)` and `useShareLink(table, id)`.
- **Inputs are MaybeRefOrGetter.** Pass a plain value, a ref, a computed or a getter (`() => route.params.id`). The composable reads it reactively and follows every change.
- **An empty input pauses a read.** An `undefined`, `null`, empty or whitespace-only id, address or term skips the query: nothing is sent, and nothing is loading.
- **A call in the old shape warns.** In development, passing a bare value, ref or getter where the options object goes logs a warning naming the new call.

## What it returns

A plain object, typed `Use<Name>Return`, of refs and functions. Destructure it freely: every value in it is a ref, so destructuring keeps it reactive.

<table>
<thead>
  <tr>
    <th>
      Name
    </th>
    
    <th>
      For
    </th>
    
    <th>
      Means
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        data
      </code>
      
      , or a name for what it holds (<code>
        results
      </code>
      
      , <code>
        messages
      </code>
      
      , <code>
        sessions
      </code>
      
      )
    </td>
    
    <td>
      reads
    </td>
    
    <td>
      The value. <code>
        undefined
      </code>
      
       until the first read lands, while paused, and after a failed read. <code>
        null
      </code>
      
       when the server answered that there is nothing (no such email). A list that is empty while loading says so in its own doc
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        isLoading
      </code>
    </td>
    
    <td>
      reads
    </td>
    
    <td>
      <code>
        true
      </code>
      
       until the first read for the current inputs lands. <code>
        false
      </code>
      
       while paused, and once a read has failed
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        isPending
      </code>
    </td>
    
    <td>
      actions
    </td>
    
    <td>
      <code>
        true
      </code>
      
       while an action runs
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        error
      </code>
    </td>
    
    <td>
      both
    </td>
    
    <td>
      <code>
        null
      </code>
      
      , or why the last read or action failed: <code>
        { code, data, message }
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        isRefused
      </code>
    </td>
    
    <td>
      admin reads
    </td>
    
    <td>
      <code>
        true
      </code>
      
       when the server refused the caller the read, such as a member who is no administrator. <code>
        useAdmin
      </code>
      
      , <code>
        useAuditLog
      </code>
      
       and <code>
        useFlagAdmin
      </code>
      
       have it
    </td>
  </tr>
</tbody>
</table>

### `error`

`error` is the same `{ code, data, message }` that [`getBackendError`](https://nuxt-backend.dev/docs/build/data/read-write/errors) reads, so one reader handles a composable's failure and a failure you caught yourself:

- **A refusal** carries its catalog code and fields: `unauthenticated`, `rate_limited` with `retryAfter`, `insufficient_credits` with `balance` and `need`, and the rest on [Errors](https://nuxt-backend.dev/docs/reference/backend/errors).
- **Anything else** reads as `unavailable` with service `backend` and reason `unexpected`: a function that crashed, which production words as "Server Error", or an app's own `ConvexError('…')`. That does not mean a service is down: it means the failure carried no code. Its `message` is the sentence the app wrote, or "Something went wrong.", never the platform's wrapper. In development the original error is logged to the console too, and rides along as the value's non-enumerable `cause`.
- **message** is a sentence to show a person. Branch on `code`, never on `message`.

A composable with both a read and actions holds the last action's failure first, and the read's when no action has failed. An action clears its own failure when the next one starts, and signing out clears it too.

```vue
<script setup lang="ts">
const { sessions, revoke, isPending, error } = useSessions()
</script>

<template>
  <p v-if="error?.code === 'rate_limited'">Too many tries. Wait a moment.</p>
  <p v-else-if="error">{{ error.message }}</p>
  <button v-for="session in sessions" :key="session.id" :aria-disabled="isPending || undefined" @click="isPending || revoke(session.id)">
    Sign out {{ session.current ? 'this device' : 'another device' }}
  </button>
</template>
```

## Reads never throw, actions reject

- **A read never throws.** A refused or crashed query lands in `error`, and the page keeps rendering. Nothing to wrap in `try`.
- **An action resolves or rejects.** It resolves with its result, or rejects with the error the call threw, as the call threw it, and mirrors it into `error`. Await it in a `try` when the next step depends on it; otherwise let `error` show the failure.

```ts
try {
  await revoke(id)
  toast('Signed out.')
}
catch (cause) {
  // `error` already holds getBackendError(cause) ?? unavailable/unexpected.
}
```

## Step machines never reject

`useLoginFlow` and `useEmailChange` drive a form through steps (`request-code`, `verify-code`, …). Their actions never reject: a failed step stays where it is, with the reason in `error` and a `retryAfter` (in seconds) after a rate limit, so a form never needs a `try`.

Their `error` is the same `{ code, data, message }`, and `isPending` is `true` while a step's call runs. An address the flow refuses before sending anything reads as `invalid_input` on `email`, with your `validateEmail` sentence as `message`. Unlike the other composables, `error` is a writable ref: a form can set it to `null` when the person starts over.

## Which composables follow them

Every composable of the package follows every rule on this page:

- **Data:** `useSearch`, `useWorkflowStatus`, `useEmailStatus`, `useSandboxInbox` and `useSessions`.
- **Billing:** `useBilling`, `useCredits`, `useFeatures`, `useGifts`, `useOrders`, `useUsage`, `useAiStream` and `useReferrals`.
- **Auth:** `useAuth`, `useAccount`, `useWorkspace`, `usePasskeys`, `useLoginFlow`, `useEmailChange`, `useConsents`, `useAccessPhase`, `useInvite`, `useAccessAdmin`, `useWaitlist` and `useWaitlistAdmin`.
- **AI, files and notifications:** `useJob`, `useChat`, `useShareLink`, `useNotifications`, `useNotificationInbox`, `usePushSubscription` and `useEmailPreferences`.

Which of the fields above each one returns, read from its `Use<Name>Return` type (a read has `isLoading`, an action `isPending`, and both `error`). The table is generated from the code:

<table>
<thead>
  <tr>
    <th>
      Composable
    </th>
    
    <th>
      <code>
        isLoading
      </code>
    </th>
    
    <th>
      <code>
        isPending
      </code>
    </th>
    
    <th>
      <code>
        error
      </code>
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        useAuth
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useLoginFlow
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useEmailChange
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useWorkspace
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useSearch
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useBilling
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useFeatures
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useCredits
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        usePricing
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        usePlanChange
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useBillingSection
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useOrders
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useUsage
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useGifts
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useGiftList
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useGiftForm
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useWithdrawal
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useReferrals
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useReferralInvite
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useReferralAdmin
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        usePasskeys
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useTwoFactor
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useSessions
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useSignInAlerts
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useReauthentication
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useAuditLog
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useAccount
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useConsents
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useAdmin
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useFlag
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useFlagAdmin
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useAccessPhase
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useInvite
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useMemberTicket
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useAccessAdmin
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useWaitlist
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useWaitlistAdmin
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useShareLink
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useUploadField
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useNotifications
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useEmailPreferences
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useEmailLink
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        usePushSubscription
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useAnnouncements
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useAnnouncementsAdmin
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useContactForm
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useReportForm
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useReportAppeal
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useOnboarding
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useActivation
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useExperiment
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useAppShell
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useInboxAdmin
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useEmailStatus
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useSandboxInbox
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useWorkflowStatus
      </code>
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useAiStream
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useJob
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useChat
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useHumanCheck
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      yes
    </td>
    
    <td>
      yes
    </td>
  </tr>
</tbody>
</table>

Auth has a few shapes of its own:

- **An action resolves with its data, not the auth client's answer.** The Better Auth client answers a refusal with `{ data, error }` instead of throwing. The actions unwrap it, so `useWorkspace().create` resolves with the new workspace.
- **A refusal reads as the catalog's code.** A banned account signing in is `forbidden` with reason `banned` (and `until`, when the ban ends), an auth route's 401 is `unauthenticated`, and a 429 is `rate_limited` with `retryAfter`. A wrong or expired code, an invalid address and a taken workspace slug are `invalid_input` on `otp`, `email` or `slug`. Any other auth refusal reads as `unavailable` with reason `unexpected`. Each keeps the auth server's sentence.
- **An action rejects with the Error the unwrap builds.** It carries the server's message, and the auth client's error is its `cause`, which `getBackendError` reads.
- **Loading a list is a read.** `usePasskeys().refresh`, and the passkey list it loads on mount, never reject: a failed load lands in `error`. `useWorkspace` reads its workspace state the same way.
- **useWorkspace().getInvitation resolves null** for an invitation that does not exist or is no longer pending, which Better Auth answers with a bare 400. A refusal with a code rejects, like any other failure.

Billing has a few shapes of its own:

- **useOrders and useUsage page through provider history.** Loading a page (on mount, `next`, `previous`, `goTo`, `refresh`) is a read: it never rejects, and a failed load lands in `error`. `useOrders().invoice` is an action.
- **useAiStream reports a stream as status.** `isPending` covers only the wait for the server to accept `start`; `isStreaming` covers the stream after that.
- **A missing function rejects when it is called.** An action whose function your backend does not export (no `portal` without `generateCustomerPortalUrl`) rejects with the package's own sentence, which `error` keeps.


## Sitemap

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