---
title: "Sign users in"
description: "Sign people in with a sign-in code or a passkey: useLoginFlow drives every step, <AuthForm> renders it at /login, codes work only in the browser that asked, a passkey is offered after the first code, and passkey-only accounts recover with a code of their own."
canonical_url: "https://nuxt-backend.dev/docs/build/auth/sign-in"
---
# Sign users in

> Sign people in with a sign-in code or a passkey: useLoginFlow drives every step, <AuthForm> renders it at /login, codes work only in the browser that asked, a passkey is offered after the first code, and passkey-only accounts recover with a code of their own.

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.

- [Try it live in the playground](https://nuxt-backend.dev/login)
- [API reference](https://nuxt-backend.dev/docs/reference/api/use-login-flow)
- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-login-flow.ts)

A person signs in with a code sent to their address, then saves a passkey, so the next sign-in needs no code. The module mounts the whole flow at `/login`, and `useLoginFlow()` runs it on a page of your own. It is the only way to sign in: `useAuth()` reads the session and signs out, nothing more.

Better Auth's email OTP and passkey plugins do the work, inside your Convex deployment. The package adds the step machine, the form, passkey autofill, the bot check before a code goes out, and the limits on sending and checking codes. It also binds each code to the browser that asked for it, offers a passkey after a code, keeps the browser's passkey list in step with the account, and lets an account turn codes off.

## How a sign-in goes

1. The person types their address and asks for a code. A [bot check](https://nuxt-backend.dev/docs/build/auth/sign-in/bots) runs first, out of sight.
2. They type the code from their inbox, in the same browser. The first sign-in creates the account and a personal workspace.
3. The flow offers to save a passkey. Next time, the passkey signs them in.

There are no passwords, no social sign-in and no magic links ([Email codes and passkeys only](https://nuxt-backend.dev/docs/start/concepts/principles#email-codes-and-passkeys-only)). In development the code also prints in the `convex dev` console, so you can sign in before email is connected ([Develop with real sandboxes](https://nuxt-backend.dev/docs/develop/sandboxes)).

## Use the ready-made page

`/login` renders `<AuthForm>`, and every page guarded with `definePageMeta({ auth: true })` sends signed-out visitors there. You write nothing. Try it here:

<demo-sign-in>



</demo-sign-in>

To restyle the form or write your own, see [Build a custom sign-in page](https://nuxt-backend.dev/docs/build/auth/sign-in/custom-page).

## Drive the flow from your own page

`useLoginFlow()` holds the current step, the fields, the pending flag and the failure. Bind the fields to your inputs and call the current step's action:

```vue [app/pages/login.vue]
<script setup lang="ts">
const flow = useLoginFlow({ onSuccess: () => navigateTo('/strips') })
const { step, email, otp, isPending, error, passkeyRequired } = flow
</script>

<template>
  <form v-if="step === 'choose' || step === 'request-code'" @submit.prevent="isPending || flow.sendCode()">
    <input v-model="email" type="email" autocomplete="username webauthn">
    <button type="submit" :aria-disabled="isPending || undefined">Email me a code</button>
    <button type="button" @click="flow.signInWithPasskey()">Use a passkey</button>
  </form>
  <form v-else-if="step === 'verify-code'" @submit.prevent="isPending || flow.verifyCode()">
    <input v-model="otp" inputmode="numeric" autocomplete="one-time-code">
    <button type="submit" :aria-disabled="isPending || undefined">Sign in</button>
  </form>
  <div v-else-if="step === 'passkey-offer'">
    <button type="button" @click="flow.addPasskey()">Save a passkey</button>
    <button v-if="!passkeyRequired" type="button" @click="flow.skipPasskey()">Not now</button>
  </div>
  <p v-if="error" role="alert">{{ error.message }}</p>
</template>
```

A busy button is `aria-disabled` and ignores the press. `disabled` would drop keyboard focus to the page ([Accessibility](https://nuxt-backend.dev/docs/build/ui/accessibility)).

### The steps

<table>
<thead>
  <tr>
    <th>
      Step
    </th>
    
    <th>
      What the person does
    </th>
    
    <th>
      Next step
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        choose
      </code>
    </td>
    
    <td>
      Picks a passkey or a code.
    </td>
    
    <td>
      <code>
        request-code
      </code>
      
      , <code>
        recover
      </code>
      
      , or done after a passkey
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        request-code
      </code>
    </td>
    
    <td>
      Types an address. <code>
        sendCode()
      </code>
      
       emails a code.
    </td>
    
    <td>
      <code>
        verify-code
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        verify-code
      </code>
    </td>
    
    <td>
      Types the code. <code>
        verifyCode()
      </code>
      
       signs in, or creates the account.
    </td>
    
    <td>
      <code>
        passkey-offer
      </code>
      
      , or <code>
        age
      </code>
      
       for a new account when the app sets a minimum age
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        passkey-offer
      </code>
    </td>
    
    <td>
      Saves a passkey with <code>
        addPasskey()
      </code>
      
      , or declines with <code>
        skipPasskey()
      </code>
      
      .
    </td>
    
    <td>
      done, and <code>
        onSuccess
      </code>
      
       runs
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        age
      </code>
    </td>
    
    <td>
      Types their age, the first time only. <code>
        submitAge()
      </code>
      
       checks it against the minimum.
    </td>
    
    <td>
      <code>
        passkey-offer
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        recover
      </code>
    </td>
    
    <td>
      Types their address and recovery code, for a passkey-only account. <code>
        recover()
      </code>
      
       checks both.
    </td>
    
    <td>
      <code>
        passkey-offer
      </code>
      
      , which can't be skipped
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        undeliverable
      </code>
    </td>
    
    <td>
      Reads that the address can't receive email, and tries another.
    </td>
    
    <td>
      <code>
        request-code
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        waitlisted
      </code>
    </td>
    
    <td>
      Reads their place on the waitlist ("You're #48 of 1,204", from <code>
        waitlist
      </code>
      
      ), while the app is in early access.
    </td>
    
    <td>
      <code>
        invite-code
      </code>
      
      , when they have a code
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        invite-code
      </code>
    </td>
    
    <td>
      Types an invite code, while the app is invite only. <code>
        redeemInviteCode()
      </code>
      
       checks it.
    </td>
    
    <td>
      <code>
        passkey-offer
      </code>
    </td>
  </tr>
</tbody>
</table>

`passkey-offer` and `recover` are the sign-in security steps ([The passkey offer](#the-passkey-offer), [Passkey-only accounts](#passkey-only-accounts)). Four steps come with features of their own:

- `age` comes with a minimum age ([Set a minimum age](https://nuxt-backend.dev/docs/build/auth/accounts/consents#set-a-minimum-age)). The new address is asked once, after its code checked, and sends the same code again with the age.
- `undeliverable` arrives with [suppressed addresses](https://nuxt-backend.dev/docs/build/email/delivery/suppressions#what-a-person-sees-at-sign-in). It shows the same words whether the address has an account or not.
- `waitlisted` and `invite-code` come with [launch phases](https://nuxt-backend.dev/docs/build/growth/launch); the waitlist records the entry as the code checks ([Run a waitlist](https://nuxt-backend.dev/docs/build/growth/launch/waitlist)).

### Its options and fields

`useLoginFlow(options?)` takes:

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        onSuccess
      </code>
    </td>
    
    <td>
      none
    </td>
    
    <td>
      Runs once the person is signed in and the flow is done, for example a <code>
        navigateTo
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        validateEmail
      </code>
    </td>
    
    <td>
      a basic shape check
    </td>
    
    <td>
      <code>
        (email) => boolean | string
      </code>
      
       checks the address before a code goes out. A string is your own message.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        autofill
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      Offers saved passkeys in the email field's autofill: see <a href="#passkey-autofill">
        passkey autofill
      </a>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        preferLastMethod
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      Opens on the way this browser last signed in.
    </td>
  </tr>
</tbody>
</table>

It returns:

<table>
<thead>
  <tr>
    <th>
      Name
    </th>
    
    <th>
      What it holds
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        step
      </code>
    </td>
    
    <td>
      The current step, from the table above.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        email
      </code>
      
      , <code>
        otp
      </code>
      
      , <code>
        inviteCode
      </code>
      
      , <code>
        age
      </code>
      
      , <code>
        recoveryCode
      </code>
    </td>
    
    <td>
      The fields. Bind them to your inputs. Once <code>
        recover()
      </code>
      
       signed in, <code>
        recoveryCode
      </code>
      
       holds the new code that replaced the used one, to show once.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        lastMethod
      </code>
    </td>
    
    <td>
      How this browser last signed in: <code>
        'passkey'
      </code>
      
      , <code>
        'email-otp'
      </code>
      
       or <code>
        null
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        passkeyRequired
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
      
       on <code>
        passkey-offer
      </code>
      
       after a recovery, where <code>
        skipPasskey()
      </code>
      
       does nothing.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        isPending
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
      
       while a step's call runs.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        error
      </code>
    </td>
    
    <td>
      Why the last step failed, as <code>
        { code, data, message }
      </code>
      
      . Set it to <code>
        null
      </code>
      
       to clear it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        retryAfter
      </code>
    </td>
    
    <td>
      After a rate-limit refusal, the seconds to wait. <code>
        null
      </code>
      
       otherwise.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        emailValid
      </code>
    </td>
    
    <td>
      Whether <code>
        email
      </code>
      
       passes <code>
        validateEmail
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sendCode()
      </code>
      
      , <code>
        verifyCode()
      </code>
      
      , <code>
        addPasskey()
      </code>
      
      , <code>
        skipPasskey()
      </code>
      
      , <code>
        submitAge()
      </code>
      
      , <code>
        recover()
      </code>
      
      , <code>
        redeemInviteCode()
      </code>
    </td>
    
    <td>
      The step actions.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        signInWithPasskey()
      </code>
    </td>
    
    <td>
      Signs in with a passkey saved on this device, through the browser's prompt.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        goTo(step)
      </code>
      
      , <code>
        reset()
      </code>
    </td>
    
    <td>
      Moves to a step, or back to the first one with every field cleared.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bind
      </code>
    </td>
    
    <td>
      Attribute bindings for your own markup, such as <code>
        bind.codeInput
      </code>
      
      , <code>
        bind.submit
      </code>
      
       and <code>
        bind.passkeyButton
      </code>
      
       (<a href="https://nuxt-backend.dev/docs/build/ui/customize/headless">
        Build on the composables
      </a>
      
      ).
    </td>
  </tr>
</tbody>
</table>

## Codes work only where they were asked for

A sign-in code works only in the browser that asked for it.

- **Bound to the browser.** Asking for a code sets an HttpOnly cookie on the auth route, tagged for sign-in: a MAC of that one code, which a newer code replaces. Checking the code needs the same cookie, and a check without it costs no guess. A code read over someone's shoulder, or typed into a phishing page, signs nobody in elsewhere.
- **Short and capped.** A code lives five minutes, and three wrong guesses end it. The address may check ten codes an hour, however many went out.
- **Tells the person who asked.** The email names the device that asked, an approximate place and the time, such as "Requested from Chrome on macOS, near Lisbon, Portugal, at 27 Oct 2026, 14:02 WET." The place and the time zone come from the host's IP geolocation where it gives one, such as Vercel's, and are left out otherwise (the time then reads in UTC). Only known browser and system names, letters for a place, and real time zones reach the email, so a forged header writes nothing into it. A person who didn't ask knows to ignore the email (the `otp` template's `requestedFrom`, [Templates](https://nuxt-backend.dev/docs/build/email/templates)).
- **A code, never a link.** Corporate mail scanners open every link in a message, which would spend a sign-in link before the person sees it. A code survives them.

A code typed in another browser is refused as `invalid_input` on `otp`, with reason `other_browser`. The person reads "This code works only in the browser where you asked for it." and asks again there.

Better Auth's email OTP plugin sets the length (six digits), the five minutes and the three guesses. It has no browser binding, so the package adds it (checked on 2026-11-07, Better Auth 1.7).

## The passkey offer

After a code sign-in, the flow stops at `passkey-offer` and asks once: save a passkey, so the next sign-in needs no code.

The offer is explicit because the browser won't make it. Chrome's automatic passkey upgrade only fires after a password sign-in, and this app has no passwords ([Passkey automatic upgrades](https://developer.chrome.com/blog/passkey-automatic-upgrades)).

- **Only where it can work.** The flow reads the browser's `getClientCapabilities()` first. A browser without WebAuthn, or whose capabilities name neither a passkey provider on the device nor a phone over the hybrid transport, skips the offer, and `onSuccess` runs at once.
- **Once a sign-in.** "Not now" signs the person in. The next code sign-in in this browser asks again.
- **After an invite or a gift too.** The offer follows every first sign-in, a workspace invitation and a gift claim included.

`<AuthForm>` renders the offer in its `passkey-offer` slot. On your own page, render the step, or call `skipPasskey()` to leave it out.

## Keep the browser's passkey list in step

A passkey removed on `/security` stays on the device until the browser hears about it. The package tells the browser through the WebAuthn Signal API, so the device stops offering a passkey that no longer works.

<table>
<thead>
  <tr>
    <th>
      Signal
    </th>
    
    <th>
      Sent when
    </th>
    
    <th>
      What the device does
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        signalUnknownCredential
      </code>
    </td>
    
    <td>
      The server refuses a passkey it doesn't know, such as one removed from the account.
    </td>
    
    <td>
      Hides or removes that passkey.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        signalAllAcceptedCredentials
      </code>
    </td>
    
    <td>
      The passkey list loads on <code>
        /security
      </code>
      
      , and after a passkey is removed.
    </td>
    
    <td>
      Keeps only the passkeys the account still holds.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        signalCurrentUserDetails
      </code>
    </td>
    
    <td>
      The name or the email address changes.
    </td>
    
    <td>
      Shows the new name and address on the passkey.
    </td>
  </tr>
</tbody>
</table>

Every passkey of an account is registered with one user handle, the account's id, so a signal can name the account's passkeys: Better Auth gives each passkey a random handle it never stores, and the package replaces it in the registration options. A passkey saved before that keeps its own handle, which the list and details signals can't reach; the unknown-credential signal still does. Chrome and Edge 132 and Safari 26 support the signals. Other browsers skip them, and nothing else changes ([WebAuthn Signal API](https://developer.chrome.com/docs/identity/webauthn-signal-api)). `usePasskeys().capabilities` holds what `getClientCapabilities()` reported, for your own markup ([Manage passkeys and sessions](https://nuxt-backend.dev/docs/build/auth/accounts/security#passkeys)).

## Passkey-only accounts

A person with a passkey can turn sign-in codes off for their account. A stolen mailbox then can't sign in to it.

- **Turning it on** happens on `/security`, or through `usePasskeys().setPasskeyOnly(true)`. It takes a [recent sign-in](https://nuxt-backend.dev/docs/build/auth/access/step-up) and at least one passkey, and answers with a recovery code, shown once. It signs every other session of the account out, so one a code opened doesn't outlive the switch ([Passkey-only](https://nuxt-backend.dev/docs/build/auth/accounts/security#passkey-only)).
- **Codes are refused.** A code request for the account looks the same as any other, with the same answer, cookie and limits, so nobody learns how an account signs in. No code goes out: the email (the `otp` template with `reason: 'passkey-only'`) says the account signs in with a passkey, and points to "Lost your passkey?". In an app that turns passwords on, a password-reset code is refused the same way, and a password never opens a session for the account.
- **Recovery.** "Lost your passkey?" on `choose` moves to `recover`. The person types their address and recovery code, and `recover()` checks both. The flow then stops at `passkey-offer` with `passkeyRequired`, and finishes only once a new passkey is saved. Until then the session is a recovery session: it lasts fifteen minutes, and every route but saving a passkey, reading the session and signing out refuses it (`forbidden`, reason `passkey_required`), and it gets no Convex token, so no function runs as the account. The used recovery code stops working, and `recoveryCode` holds the new one, which `<AuthForm>` shows once beside the offer.
- **The person hears of it.** Turning codes off or back on emails the account and lands on its activity as `auth.passkey_only_changed`. A recovery emails the address (the `passkeyRecovered` template): the device, place and time it came from, and a link to `/security` to sign other devices out ([Alert people to new sign-ins](https://nuxt-backend.dev/docs/build/auth/accounts/alerts)).

A person who lost every passkey and the recovery code asks you. An administrator turns passkey-only off from the account's drawer in the Users tab, after checking who asks ([Run the admin console](https://nuxt-backend.dev/docs/build/auth/admin)).

## Passkey autofill

A person who saved a passkey can pick it from the email field's autofill, the way a browser fills a saved password. No code, and no prompt to open first. `<AuthForm>` does this, opens on the way this browser last signed in, and marks that method **Last used**.

On your own page, turn both on and mark the email field for passkeys. Its `autocomplete` must end in `webauthn`:

```vue [app/pages/login.vue]
<script setup lang="ts">
const flow = useLoginFlow({
  autofill: true,
  preferLastMethod: true,
  onSuccess: () => navigateTo('/strips'),
})
const { step, email, lastMethod } = flow
</script>

<template>
  <div v-if="step === 'choose'">
    <button type="button" @click="flow.signInWithPasskey()">
      Sign in with passkey <span v-if="lastMethod === 'passkey'">Last used</span>
    </button>
    <button type="button" @click="flow.goTo('request-code')">
      Continue with email <span v-if="lastMethod === 'email-otp'">Last used</span>
    </button>
  </div>
  <form v-else-if="step === 'request-code'" @submit.prevent="flow.sendCode()">
    <input v-model="email" type="email" autocomplete="username webauthn">
    <button type="submit">Email me a code</button>
  </form>
</template>
```

- **When it asks.** On the `choose` and `request-code` steps, once the page shows a field marked `webauthn`. A challenge lasts five minutes, so the flow renews it every four and a half minutes while the page is in view.
- **What the person sees.** A picked passkey finishes the flow, as `signInWithPasskey()` does. A passkey the server refuses, such as one removed from the account but still on the device, lands in `error` as `invalid_input` on `passkey`. A browser without conditional mediation offers nothing in the field, and the passkey button still works.
- **Where the last method comes from.** Better Auth's [`lastLoginMethod`](https://better-auth.com/docs/plugins/last-login-method) plugin records each sign-in on the account (`user.lastLoginMethod`) and in a cookie that lasts 30 days. The cookie holds the method's name only. The server render reads it too, so the page renders the same on both sides.
- **The cookie asks first.** It is not strictly necessary, so it is set only once the person allows it in the consent manager. Without it, `lastMethod` is `null` and the page opens on `choose`. A browser that never chose, or declined, gets no cookie ([Ask before optional storage](https://nuxt-backend.dev/docs/build/auth/accounts/consents#ask-before-optional-storage)).
- **Its limits.** Every passkey sign-in starts with a challenge the server stores, so the challenge route is limited per client and for the whole deployment ([Privileged routes](https://nuxt-backend.dev/docs/ship/security/rate-limits#privileged-routes)).

To tie the cookie to a consent of your own, pass your own `lastLoginMethod` in `authOptions.plugins`. Better Auth names a code sign-in `email-otp` and a passkey's `passkey` itself. Keep `storesLastSignInCookie` as the check to follow the consent manager's choice, or write your own:

```ts [backend/auth.ts]
import { lastLoginMethod } from 'better-auth/plugins'
import { setupAuth, storesLastSignInCookie } from 'nuxt-backend/auth'

export const { authComponent, createAuth, getAuthUser } = setupAuth(components, query, {
  email,
  authOptions: {
    plugins: [lastLoginMethod({
      storeInDatabase: true,
      beforeStoreCookie: ctx => storesLastSignInCookie(ctx) && ctx.getCookie('consent') === 'yes',
    })],
  },
})
```

## Read the session

`useAuth()` holds the session in every page and component. It reads, and it signs out:

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

<tbody>
  <tr>
    <td>
      <code>
        user
      </code>
    </td>
    
    <td>
      The signed-in account (<code>
        id
      </code>
      
      , <code>
        email
      </code>
      
      , <code>
        name
      </code>
      
      , <code>
        image
      </code>
      
      , <code>
        banned
      </code>
      
      ), or <code>
        null
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        session
      </code>
    </td>
    
    <td>
      The current session, or <code>
        null
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        role
      </code>
    </td>
    
    <td>
      The app-wide role: <code>
        user
      </code>
      
      , <code>
        admin
      </code>
      
       or one of yours (<a href="https://nuxt-backend.dev/docs/build/auth/access/roles">
        Roles
      </a>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        hasRole(role)
      </code>
    </td>
    
    <td>
      Whether the account holds the role, or one of a list.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        isSignedIn
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
      
       once a session is loaded.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        isReady
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
      
       once someone is signed in and the backend connection holds their token: what a signed-in read waits for.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        isLoading
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
      
       while the session is still resolving, on the first load and after a refresh.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        impersonating
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
      
       while an administrator visits the account (<a href="https://nuxt-backend.dev/docs/build/auth/admin/impersonation">
        Impersonation
      </a>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        signOut()
      </code>
    </td>
    
    <td>
      Ends the session in this tab.
    </td>
  </tr>
</tbody>
</table>

`isSignedIn` and `isLoading` come from the session. On a page load the session is back a moment before the backend connection holds its token, and a query of a signed-in tier (`authed`, `workspace`, `admin`) asked in that moment is refused `unauthenticated`. `isReady` reads the connection: pass `'skip'` until it is `true` ([Signed-in reads](https://nuxt-backend.dev/docs/build/data/read-write#signed-in-reads)). The way this browser last signed in is `useLoginFlow().lastMethod` ([its fields](#its-options-and-fields)), for a sign-in page that offers it first.

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

const { user, signOut } = useAuth()

async function leave() {
  await signOut()
  await navigateTo('/')
}
</script>

<template>
  <p>Signed in as {{ user?.email }}</p>
  <button type="button" @click="leave">Sign out</button>
</template>
```

Where a person goes after `signOut()` is up to you. A session that ends elsewhere, in another tab or from another device, is handled for you ([When the session ends](https://nuxt-backend.dev/docs/build/auth/access/pages#when-the-session-ends)). The active workspace is on [`useWorkspace()`](https://nuxt-backend.dev/docs/build/auth/workspaces). In a Convex function, the tiers of [Protect backend functions](https://nuxt-backend.dev/docs/build/auth/access/functions) give you `ctx.user`.

## What happens when…

The step actions never reject. A failed step stays where it is, with the reason in `error`, so your form needs no `try`. Branch on `error.code`:

<table>
<thead>
  <tr>
    <th>
      <code>
        error.code
      </code>
    </th>
    
    <th>
      When
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#rate_limited">
        <code>
          rate_limited
        </code>
      </a>
    </td>
    
    <td>
      Too many requests. <code>
        retryAfter
      </code>
      
       holds the seconds to wait.
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#forbidden">
        <code>
          forbidden
        </code>
      </a>
      
      , reason <code>
        banned
      </code>
    </td>
    
    <td>
      The account is banned. For a ban that ends, <code>
        until
      </code>
      
       holds when (epoch ms), and the message names it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        sign_in_refused
      </code>
    </td>
    
    <td>
      Your <a href="https://nuxt-backend.dev/docs/build/auth/sign-in/hooks#gate-who-signs-in">
        <code>
          canSignIn
        </code>
      </a>
      
       refused, and <code>
        message
      </code>
      
       is yours.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        bot_check
      </code>
    </td>
    
    <td>
      The <a href="https://nuxt-backend.dev/docs/build/auth/sign-in/bots">
        bot check
      </a>
      
       failed.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        age_required
      </code>
    </td>
    
    <td>
      A new address checked its code while the app sets a minimum age, and sent none. The code is not used up; the flow moves to <code>
        age
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        under_age
      </code>
    </td>
    
    <td>
      The age typed is under the minimum, or this browser answered under it today.
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#invalid_input">
        <code>
          invalid_input
        </code>
      </a>
      
       on <code>
        email
      </code>
      
       or <code>
        otp
      </code>
    </td>
    
    <td>
      A malformed address, or a wrong or expired code.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        invalid_input
      </code>
      
       on <code>
        otp
      </code>
      
      , reason <code>
        other_browser
      </code>
    </td>
    
    <td>
      The code was asked for in another browser.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        invalid_input
      </code>
      
       on <code>
        recoveryCode
      </code>
    </td>
    
    <td>
      A wrong or used recovery code, or an address without one.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        passkey_required
      </code>
    </td>
    
    <td>
      A recovery session tried anything but saving its passkey.
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#unavailable">
        <code>
          unavailable
        </code>
      </a>
    </td>
    
    <td>
      Any other failure, with the auth server's sentence as <code>
        message
      </code>
      
      .
    </td>
  </tr>
</tbody>
</table>

Checking codes has a budget of its own: ten checks an hour per address, however many codes went out ([What the user sees](https://nuxt-backend.dev/docs/ship/security/rate-limits#what-the-user-sees)).

## Limits

- **Codes.** Five sends a minute per address, 300 an hour for the whole deployment, and ten checks an hour per address ([Tune rate limits](https://nuxt-backend.dev/docs/ship/security/rate-limits)). Every code is an email against your provider's quota ([Resend](https://nuxt-backend.dev/docs/services/resend)).
- **Passkeys.** The browser and the device decide what a passkey prompt looks like. A browser without WebAuthn signs in with codes only.
- **User verification.** Every passkey asks the device to check the person: a fingerprint, a face or the device's PIN (`userVerification: 'required'`), when it is saved and at every sign-in, and the server refuses a passkey that skipped it, at sign-in and in `useReauthentication().withPasskey`. A security key with no PIN set can't be saved until it has one. If you pass your own `passkey(...)`, keep `authenticatorSelection: { userVerification: 'required' }` in it.
- **Signals.** A browser without the Signal API keeps offering a removed passkey until the person deletes it from the device.
- **Recovery.** One recovery code per account, at least 100 bits. Its route is limited per client and for the whole deployment, never per address, so nobody can lock a person out of their own recovery. A person who loses it with every passkey gets back in only through an administrator.

## Test it

End to end, read the code back from the dev inbox. `inbox --json` reads once, so poll until a code arrives ([Run end-to-end tests](https://nuxt-backend.dev/docs/develop/testing/e2e)):

```ts [tests/sign-in.spec.ts]
import { execFileSync } from 'node:child_process'
import { expect, test } from '@playwright/test'

const latestCode = (address: string) =>
  JSON.parse(execFileSync('npx', ['nuxt-backend', 'inbox', address, '--json'], { encoding: 'utf8' })).code

test('signs in with a code', async ({ page }) => {
  const address = `delivered+e2e-${Date.now()}@resend.dev`
  await page.goto('/login')
  await page.getByRole('button', { name: 'Continue with email' }).click()
  await page.getByRole('textbox', { name: 'Email' }).fill(address)
  await page.getByRole('button', { name: 'Email me a code' }).click()

  await expect.poll(() => latestCode(address), { timeout: 30_000 }).toBeTruthy()
  await page.getByRole('textbox', { name: 'Code' }).fill(latestCode(address))
  await page.getByRole('button', { name: 'Sign in' }).click()
  await page.getByRole('button', { name: 'Not now' }).click()

  await expect(page).toHaveURL('/')
})
```

## Coming from the current API

`resolveSignInMethod` is deprecated: Better Auth 1.7 names a code sign-in `email-otp` itself, so drop `customResolveMethod: resolveSignInMethod` from your own `lastLoginMethod`. It still works until a later minor release removes it. Passkeys now require user verification: a device that signs in without checking the person's fingerprint, face or PIN is refused.

A passkey saved under 0.2, which asked for verification as `preferred`, by a security key with no PIN was stored unverified, and it is now refused at sign-in and in `useReauthentication().withPasskey`. Chrome offers to set a PIN on such a key; a U2F-only key can never verify. The passkey row keeps no verification flag, so you can't find those accounts in advance. The refusal is `invalid_input` on `passkey`, whose label tells a security key's owner to set a PIN, or reason `passkey_cancelled` when the browser gives up on the key itself. The person signs in with an email code and saves a new passkey. A passkey-only account uses its recovery code, and without one an administrator's `allowSignInCodes` ([Passkey-only accounts](#passkey-only-accounts)).

The offer step was `add-passkey`, and so was `<AuthForm>`'s slot: both are `passkey-offer` now (the `data-auth="step-add-passkey"` hook keeps its name). A code now works only in the browser that asked for it, so a test that asks in one client and checks in another fails with `other_browser`. The last-method cookie is set only once the browser allowed it in the consent manager, so a page that marks **Last used** lists `preferences` in `appConfig.backend.consent.purposes`.

## Related

- [Build a custom sign-in page](https://nuxt-backend.dev/docs/build/auth/sign-in/custom-page): `<AuthForm>`'s slots and parts, or your own markup on `useLoginFlow`.
- [Hook into sign-in and sign-up](https://nuxt-backend.dev/docs/build/auth/sign-in/hooks): `canSignIn` and the account lifecycle hooks.
- [Stop bots](https://nuxt-backend.dev/docs/build/auth/sign-in/bots): the check before a code goes out.
- [Security model](https://nuxt-backend.dev/docs/ship/security#passwordless-sign-in-and-its-rate-limits): what sign-in turns off, and why.
- [Resend](https://nuxt-backend.dev/docs/services/resend): the provider that delivers the codes.


## Sitemap

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