---
title: "Record consents"
description: "Keep a versioned record of what each person agreed to: your terms, your privacy policy and opt-ins of your own, asked again after a change. Ask before any optional storage with the consent manager, and refuse sign-ups under a minimum age."
canonical_url: "https://nuxt-backend.dev/docs/build/auth/accounts/consents"
---
# Record consents

> Keep a versioned record of what each person agreed to: your terms, your privacy policy and opt-ins of your own, asked again after a change. Ask before any optional storage with the consent manager, and refuse sign-ups under a minimum age.

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.

When someone asks what a person agreed to and when, your app should answer from a record, not a guess. Declare each document or opt-in once, with its version. The package records who accepted which version and when, asks again when you raise a version, and keeps the record with the account's export and erasure. The same ledger drives the consent manager for optional storage, and the age check at sign-up.

No provider keeps this ledger for you. Better Auth holds the account and Resend holds email topics, so the consents live in the package's `backend` component, next to the account they belong to. Nothing here is legal advice: [Compliance](https://nuxt-backend.dev/docs/ship/compliance) lists which laws reach a client app, with their sources.

## Declare your consents

Each consent is a kind with a version, in `setupAccount`:

```ts [backend/account.ts]
import { setupAccount } from 'nuxt-backend/account'
import { components } from './_generated/api'
import { audit } from './audit'
import { billing } from './billing'
import { email } from './email'

export const account = setupAccount(components, {
  audit,
  billing,
  email,
  consents: {
    terms: { version: '2026-10-01', url: '/terms', required: true },
    privacy: { version: '2026-10-01', url: '/privacy', required: true },
    gallery: { version: '2026-10-01', url: '/gallery-rules' },
  },
})

export const {
  exportAccountData, getAccountExport, eraseAccountData,
  getConsents, getConsentTerms, grantConsent, withdrawConsent, chooseStorage,
} = account.api
```

The consent functions are part of `account.api`, so `backend/account.ts` re-exports them with the rest, and the scaffold already does. `setupAuth` gets the instance as `account` too: it records the sign-up from there ([Export and delete account data](https://nuxt-backend.dev/docs/build/auth/accounts/data)).

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      What it does
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        version
      </code>
    </td>
    
    <td>
      The document's version. Raise it when the text changes, and everyone is asked again.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        url
      </code>
    </td>
    
    <td>
      Where the document lives. Every prompt links to it. The packaged terms and privacy pages live at <code>
        /legal/terms
      </code>
      
       and <code>
        /legal/privacy
      </code>
      
       (<a href="https://nuxt-backend.dev/docs/ship/compliance/privacy#legal-pages">
        Legal pages
      </a>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        required
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
      
      : a person must accept it to use the app, so sign-up asks for it. Otherwise it is an opt-in they choose.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        title
      </code>
    </td>
    
    <td>
      What the prompt calls it. Default: the <code>
        consent.kinds.<kind>
      </code>
      
       label for <code>
        terms
      </code>
      
       and <code>
        privacy
      </code>
      
      , else the kind with spaces ("Gallery rules").
    </td>
  </tr>
</tbody>
</table>

`terms` and `privacy` are names like any other. Name a kind for what the person allows: `gallery` above lets the app show their strips in a public gallery. A kind is lower-case words joined by `-` or `_`, and `storage`, `age` and `launch-news` are the package's own.

## At sign-up

`<AuthForm>` shows an agreement line linking every required kind: "By continuing, you agree to the Terms and the Privacy policy." Creating the account records each required kind at its current version. Each record holds the time and `source: 'sign-up'`. Its words are labels, so you change or translate them like any other ([Change copy and labels](https://nuxt-backend.dev/docs/build/ui/customize/labels)). A form of your own gets the same line from `useConsents().terms`.

An account an administrator creates, or your own server code, agreed to nothing yet. Nothing is recorded for it, and `<ConsentPrompt>` asks at its first visit.

A consent given before the account existed carries over. Say a person joined the [waitlist](https://nuxt-backend.dev/docs/build/growth/launch/waitlist) and ticked "Email me launch news". The package recorded that as kind `launch-news`, with the words the form showed, by a hash of their address, and the record moves to the account when they sign up. Leaving the waitlist first withdraws it.

## Ask again after a change

Raise a required kind's `version` and deploy. On their next page, everyone signed in on an older version sees `<ConsentPrompt>`: what changed, the link, and **Accept**. The page waits behind it until they accept.

- **Where it shows.** Every packaged page renders it, and the app shell will when it ships. In a layout of your own, render `<ConsentPrompt />` once.
- **Not during a visit.** An administrator visiting the account passes through, and can't accept on the person's behalf ([Impersonation](https://nuxt-backend.dev/docs/build/auth/admin/impersonation)).
- **Before onboarding.** A new account accepted at sign-up. One that did not (an administrator created it) accepts first, then [activation](https://nuxt-backend.dev/docs/build/growth/engage/activation) starts.
- **Only what is missing.** The prompt asks for each required kind not accepted at its latest version, one box each and nothing ticked for the person, and for the age of an account that never gave it. **Accept** waits for every required box.

## Read and change them in the app

`useConsents()` holds the signed-in person's consents, for a settings page of your own:

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

const { consents, grant, withdraw, isPending } = useConsents()
</script>

<template>
  <label>
    <input
      type="checkbox"
      :checked="consents.gallery?.current"
      :aria-disabled="isPending || undefined"
      @change="consents.gallery?.current ? withdraw('gallery') : grant('gallery')"
    >
    Show my strips in the public gallery
  </label>
</template>
```

It returns:

- `consents`: per kind, its `version`, `grantedAt`, and `current` when the version is the latest. A kind never accepted, or withdrawn, is absent;
- `missing`: the required kinds not yet accepted at their latest version, with `age` while the minimum age is unanswered;
- `grant(kind)` and `withdraw(kind)`, with `isPending` and `error`. `grant('age', { age })` checks an age against `minimumAge` and keeps only that it passed;
- `terms`: the required kinds with their titles and links, for an agreement line of your own, and `minimumAge`;
- `storage`, `allowStorage(choice)` and `isAsking`, for the [consent manager](#ask-before-optional-storage).

A required kind can't be withdrawn: a person who no longer agrees deletes their account.

## Check one in a function

Read a consent where it gates what your app does with someone's data:

```ts [backend/gallery.ts]
import { query } from './_generated/server'
import { account } from './account'

export const list = query({
  args: {},
  handler: async (ctx) => {
    const strips = await ctx.db.query('strips').withIndex('publishedAt').order('desc').take(100)
    const shown = []
    for (const strip of strips) {
      if (await account.consented(ctx, { userId: strip.authorId, kind: 'gallery' })) shown.push(strip)
    }
    return shown
  },
})
```

`account.consented` is `true` only for the latest version, granted and not withdrawn. A kind you never declared throws `invalid_input` on `kind`, so a typo fails loudly instead of reading `false`.

To refuse a function until every required kind is accepted, call `account.requireConsent(ctx, { userId })` first. It throws `forbidden`, reason `consent_required`, with the `kind` still missing.

## Ask before optional storage

The package uses only strictly necessary storage by default: the session cookie, the code cookie and the sign-in state. Strictly necessary storage needs no consent banner under the ePrivacy Directive, Art. 5(3), so a default app shows none.

The consent manager turns on only when you turn on something that isn't necessary. Name what your app uses in `appConfig.backend.consent.purposes`:

```ts [app/app.config.ts]
export default defineAppConfig({
  backend: { consent: { purposes: ['replay', 'analytics'] } },
})
```

<table>
<thead>
  <tr>
    <th>
      Purpose
    </th>
    
    <th>
      What asks for it
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        preferences
      </code>
    </td>
    
    <td>
      The last-sign-in-method cookie behind <strong>
        Last used
      </strong>
      
       on the sign-in page (<a href="https://nuxt-backend.dev/docs/build/auth/sign-in#passkey-autofill">
        Passkey autofill
      </a>
      
      ), and <code>
        <UpgradePrompt :cooldown>
      </code>
      
       keeping a dismissal past the tab. It is asked whenever another purpose is, or alone when you list it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        replay
      </code>
    </td>
    
    <td>
      Session replay in your error monitoring (<a href="https://nuxt-backend.dev/docs/services/sentry">
        Sentry
      </a>
      
      ). Listing it turns replay on: the package starts it once the browser allows it, and stops it when the person withdraws (<a href="https://nuxt-backend.dev/docs/ship/operate/monitoring#what-the-preset-does">
        What the preset does
      </a>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        analytics
      </code>
    </td>
    
    <td>
      An analytics integration of yours that stores an identifier.
    </td>
  </tr>
</tbody>
</table>

While `purposes` is empty, `useConsents().storage` is `{}` and nothing renders, and the last-sign-in-method cookie is never set. Once it lists a purpose, `<ConsentPrompt>` asks once per browser, with **Allow** and **Decline** of the same weight, and each purpose off until allowed. The choice stays in a first-party cookie (`backend.storage`, six months). A signed-in person's choice also joins their ledger as kind `storage`, whose version lists the purposes they allowed (`none` for a decline), so it follows them to another browser. An administrator visiting the account is not asked.

An integration of yours listens for the choice: the `backend:storage` hook runs on the client with the choice once the browser has one, and again whenever it changes.

```ts [app/plugins/analytics.client.ts]
export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.hook('backend:storage', (choice) => {
    if (choice.analytics) startAnalytics()
    else stopAnalytics()
  })
})
```

```vue [app/components/StorageChoices.vue]
<script setup lang="ts">
const { storage, allowStorage } = useConsents()
</script>

<template>
  <label>
    <input type="checkbox" :checked="storage.preferences" @change="allowStorage({ preferences: !storage.preferences })">
    Remember how I last signed in
  </label>
</template>
```

Withdrawing takes the same one step as allowing: the same switch, on a page you link from your footer. A withdrawn purpose deletes what it stored: the `preferences` cookie is deleted at once, and the `backend:storage` hook tells the rest to stop.

The auth route sets the last-sign-in-method cookie only for a browser whose `backend.storage` cookie allows `preferences`. An app that passes its own `lastLoginMethod` plugin passes `beforeStoreCookie: storesLastSignInCookie` (from `nuxt-backend/auth`) to keep that rule.

## Set a minimum age

`setupAccount({ minimumAge })` asks a new account for its age once, after its first code, and refuses anyone under it.

```ts [backend/account.ts]
export const account = setupAccount(components, {
  audit,
  billing,
  email,
  minimumAge: 16,
})
```

- **Pick the number for where you operate.** GDPR Art. 8 lets each EU country set the age of digital consent between 13 and 16. The amended COPPA rule, in force since 2026-04-22, covers children under 13 in the US ([Set a minimum age](https://nuxt-backend.dev/docs/ship/compliance/age)).
- **A neutral question.** The `age` step asks "How old are you?" with an empty field, and never names the minimum, so the answer isn't steered.
- **Only the mailbox holder sees it.** The step follows a valid code for a new address, so it says nothing about which addresses have accounts. The code is not used up: the form sends the same code again with the age, and the check refuses a new address that sent none (`forbidden`, reason `age_required`).
- **Refused for good in this browser.** An age under the minimum is refused as `forbidden`, reason `under_age`, and no account is created. The browser keeps the refusal for a day in an HttpOnly cookie, so a second answer can't follow at once.
- **Checked where the account is made.** The age is checked again when the account is created, on every route that creates one, so no other route gets round it. An account an administrator creates is asked at its first visit instead.
- **No age is kept.** The account records kind `age` at the minimum's value with the time, never the number typed. Raising `minimumAge` asks again: `<ConsentPrompt>` asks the age of every account whose ledger holds no age at the new minimum, and refuses one under it (`forbidden`, reason `under_age`). It deletes nothing, so what happens to that account is yours ([Set a minimum age](https://nuxt-backend.dev/docs/ship/compliance/age)). Lowering the minimum asks nobody.

There is no parental-consent flow. An app aimed at children needs one of its own, and counsel.

## The record it keeps

- **One row per decision.** Each grant and each withdrawal is a row: the kind, the version, the time and where it came from. Nothing is overwritten, so the history stays readable.
- **On the trail.** Each one lands on the [activity trail](https://nuxt-backend.dev/docs/build/auth/admin/audit-log) as `consent.granted` or `consent.withdrawn`, with the kind, the version and the source, never the age.
- **In the export, out with the erasure.** The account's [export](https://nuxt-backend.dev/docs/build/auth/accounts/data#export-an-accounts-data) lists every row. Its erasure removes them, and `account.forgetEmail` removes the rows kept by an address.
- **Checked before launch.** `npx nuxt-backend doctor --prod` reports a required kind without a `url` (`consent-urls`), since the agreement line would point nowhere.

Marketing email is a topic people choose in their [email preferences](https://nuxt-backend.dev/docs/build/email/preferences), and each choice records its consent here too.

## What happens when…

<table>
<thead>
  <tr>
    <th>
      Refused with
    </th>
    
    <th>
      When
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#forbidden">
        <code>
          forbidden
        </code>
      </a>
      
      , reason <code>
        consent_required
      </code>
    </td>
    
    <td>
      A function or page needs a required kind the person hasn't accepted at its latest version. <code>
        <ConsentPrompt>
      </code>
      
       asks.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        age_required
      </code>
    </td>
    
    <td>
      A new address checked its code without an age while the app sets <code>
        minimumAge
      </code>
      
      . <code>
        useLoginFlow
      </code>
      
       moves to its <code>
        age
      </code>
      
       step.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        under_age
      </code>
    </td>
    
    <td>
      The age typed at sign-up is under <code>
        minimumAge
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        impersonating
      </code>
    </td>
    
    <td>
      An administrator's visit tries to grant or withdraw.
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#invalid_input">
        <code>
          invalid_input
        </code>
      </a>
      
      , field <code>
        kind
      </code>
    </td>
    
    <td>
      A kind <code>
        setupAccount
      </code>
      
       doesn't declare, or a required kind being withdrawn.
    </td>
  </tr>
</tbody>
</table>

## Limits

- **The ledger proves a click, not understanding.** Keep each version's text where its `url` points, so you can show what was agreed to.
- **Age is self-declared.** The package checks no document. Whether that suffices depends on your audience and the law that reaches you.
- **Cookie consent covers this package's storage.** A script you add yourself asks through `useConsents().storage` too, or it bypasses the manager.

## Test it

```ts [backend/gallery.test.ts]
import { asUser, defineBackendTestApp } from 'nuxt-backend/test'
import { expect, test } from 'vitest'
import { api } from './_generated/api'
import schema from './schema'

const testApp = defineBackendTestApp(schema, import.meta.glob('./**/*.ts'))

test('hides strips of authors who never opted in', async () => {
  const t = testApp()
  const ada = await asUser(t)
  await ada.mutation(api.strips.publish, { title: 'Monday' })
  expect(await t.query(api.gallery.list, {})).toEqual([])
})
```

## Related

- [Export and delete an account](https://nuxt-backend.dev/docs/build/auth/accounts/data): where consents are exported and erased.
- [Privacy, GDPR and cookies](https://nuxt-backend.dev/docs/ship/compliance/privacy): what the app keeps about a person, and the cookie stance.
- [Set a minimum age](https://nuxt-backend.dev/docs/ship/compliance/age): the law behind `minimumAge`.
- [Let people choose their emails](https://nuxt-backend.dev/docs/build/email/preferences): marketing topics and their consents.
- [Guardrails on growth features](https://nuxt-backend.dev/docs/start/concepts/principles#guardrails-on-growth-features): consent defaults across the package.


## Sitemap

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