---
title: "Build a custom sign-in page"
description: "Replace /login with a page of your own: restyle <AuthForm> through its slots, or drive useLoginFlow with your own markup, and keep ?redirect=, passkey autofill and every step working."
canonical_url: "https://nuxt-backend.dev/docs/build/auth/sign-in/custom-page"
---
# Build a custom sign-in page

> Replace /login with a page of your own: restyle <AuthForm> through its slots, or drive useLoginFlow with your own markup, and keep ?redirect=, passkey autofill and every step working.

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)

Your sign-in page is the first screen of your brand most people see. Put an app page at `/login` and it replaces the module's: the module detects it, skips its own and logs the override. To serve sign-in at another path, also set [`pages.login`](https://nuxt-backend.dev/docs/reference/configuration/module-options), so guarded pages send signed-out visitors there.

Better Auth ships no sign-in UI. The package ships `<AuthForm>` and the `useLoginFlow()` step machine under it, and lets you take over as much as you need, one rung of the [customization ladder](https://nuxt-backend.dev/docs/build/ui/customize) at a time:

<table>
<thead>
  <tr>
    <th>
      Rung
    </th>
    
    <th>
      What you change
    </th>
    
    <th>
      Where
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Mount
    </td>
    
    <td>
      Nothing: <code>
        /login
      </code>
      
       is there
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/auth/sign-in#use-the-ready-made-page">
        Sign users in
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Tokens
    </td>
    
    <td>
      Colors, radius, type, through <code>
        --bk-*
      </code>
      
       on <code>
        :root
      </code>
      
       and the <code>
        data-auth
      </code>
      
       hooks
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/ui/customize/tokens">
        Restyle with tokens
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Labels
    </td>
    
    <td>
      Every word, in every language
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/ui/customize/labels">
        Change copy and labels
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Slots
    </td>
    
    <td>
      One region of the form
    </td>
    
    <td>
      <a href="#restyle-authform-through-its-slots">
        below
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Swap a part
    </td>
    
    <td>
      One part everywhere, such as <code>
        AuthFormCode
      </code>
    </td>
    
    <td>
      <a href="#swap-one-part">
        below
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Composables
    </td>
    
    <td>
      Every element, on <code>
        useLoginFlow()
      </code>
      
       and its bindings
    </td>
    
    <td>
      <a href="#write-your-own-markup-on-useloginflow">
        below
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Eject
    </td>
    
    <td>
      A copy of the source you own
    </td>
    
    <td>
      <a href="#eject-the-form">
        below
      </a>
    </td>
  </tr>
</tbody>
</table>

The playground's own [/login](https://nuxt-backend.dev/login) stops at slots. To drop the package's CSS entirely, see the [Customization ladder](https://nuxt-backend.dev/docs/build/ui/customize).

## Restyle `<AuthForm>` through its slots

Each slot receives the whole flow, the object `useLoginFlow()` returns, as its props. The props are refs, so read `.value` inside a slot.

<table>
<thead>
  <tr>
    <th>
      Slot
    </th>
    
    <th>
      Replaces
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        header
      </code>
    </td>
    
    <td>
      The logo and the title.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        choose
      </code>
    </td>
    
    <td>
      The first step: the passkey button and "Continue with email", with the last method marked "Last used".
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        request-code
      </code>
    </td>
    
    <td>
      The email field. Keep <code>
        autocomplete="username webauthn"
      </code>
      
       on it, where the browser offers saved passkeys.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        verify-code
      </code>
    </td>
    
    <td>
      The code field.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        passkey-offer
      </code>
    </td>
    
    <td>
      The offer to save a passkey after a code, and the passkey a recovery requires.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        age
      </code>
      
      , <code>
        recover
      </code>
      
      , <code>
        undeliverable
      </code>
      
      , <code>
        waitlisted
      </code>
      
      , <code>
        invite-code
      </code>
    </td>
    
    <td>
      The security and launch steps of <a href="https://nuxt-backend.dev/docs/build/auth/sign-in#the-steps">
        Sign users in
      </a>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        error
      </code>
    </td>
    
    <td>
      Why the last step failed. It renders only while <code>
        error
      </code>
      
       is set.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        footer
      </code>
    </td>
    
    <td>
      Below everything.
    </td>
  </tr>
</tbody>
</table>

```vue [app/pages/login.vue]
<script setup lang="ts">
definePageMeta({ layout: false })

function done() {
  return navigateTo(resolveAuthRedirect(useRoute().query.redirect, '/strips'))
}
</script>

<template>
  <main class="sign-in">
    <AuthForm @success="done">
      <template #header>
        <img src="/logo.svg" alt="Panels">
      </template>
      <template #error="{ error, retryAfter }">
        <p role="alert">
          {{ error.value?.message }}
          <span v-if="retryAfter.value">Try again in {{ retryAfter.value }} seconds.</span>
        </p>
      </template>
    </AuthForm>
  </main>
</template>
```

`<AuthForm>` emits three events. `success` fires once the person is signed in and has saved or skipped a passkey. `step` fires on every step change, and `error` carries the message of a failed step.

## Swap one part

Every region of `<AuthForm>` is a registered part. An app component with the same name, in `app/components/`, replaces it everywhere the form renders, the packaged `/login` and the "Confirm it's you" dialog included.

<table>
<thead>
  <tr>
    <th>
      Part
    </th>
    
    <th>
      Renders
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        AuthFormHeader
      </code>
    </td>
    
    <td>
      The logo and the title.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        AuthFormChoose
      </code>
    </td>
    
    <td>
      The first step's buttons.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        AuthFormEmail
      </code>
    </td>
    
    <td>
      The email field and its button.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        AuthFormCode
      </code>
    </td>
    
    <td>
      The code field and its button.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        AuthFormPasskey
      </code>
    </td>
    
    <td>
      The passkey button and its "Last used" badge.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        AuthFormPasskeyOffer
      </code>
    </td>
    
    <td>
      The offer to save a passkey after a code sign-in.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        AuthFormError
      </code>
    </td>
    
    <td>
      The failure message.
    </td>
  </tr>
</tbody>
</table>

A part receives the flow as props, the same object a slot gets, and its bindings carry the accessibility attributes:

```vue [app/components/AuthFormCode.vue]
<script setup lang="ts">
import type { UseLoginFlowReturn } from 'nuxt-backend'

const props = defineProps<{ flow: UseLoginFlowReturn }>()
</script>

<template>
  <label class="code">
    Code from your email
    <input v-bind="props.flow.bind.codeInput" class="code-input">
  </label>
</template>
```

`doctor` lists every app component that shares a name with a part, so you know which ones you swapped ([Swap a part](https://nuxt-backend.dev/docs/build/ui/customize/parts)).

## Write your own markup on `useLoginFlow()`

`useLoginFlow()` holds the steps, the fields, `isPending` and `error`. [Sign users in](https://nuxt-backend.dev/docs/build/auth/sign-in#drive-the-flow-from-your-own-page) has a complete page and every field it returns. A page of your own has four things to keep.

### Send the person back

A guarded page puts the page the person wanted in `?redirect=`. Never navigate to it as given. `resolveAuthRedirect` (auto-imported) keeps it when it is a path of this site, and returns your fallback otherwise:

```ts [app/pages/login.vue]
const flow = useLoginFlow({
  onSuccess: () => navigateTo(resolveAuthRedirect(useRoute().query.redirect, '/strips')),
})
```

The module's own page falls back to [`redirects.afterSignIn`](https://nuxt-backend.dev/docs/reference/configuration/module-options). Read it from `useRuntimeConfig().public.backend.redirects.afterSignIn` to keep one setting for both.

### Render every step

The flow can land on any step of [the step table](https://nuxt-backend.dev/docs/build/auth/sign-in#the-steps), so give each one markup, `undeliverable`, `waitlisted` and `invite-code` included. A failed step stays where it is, with the reason in `error`. Show `error.message`, and branch on `error.code` where a failure needs its own words:

```vue [app/pages/login.vue]
<template>
  <p v-if="error?.code === 'rate_limited' && retryAfter">Too many tries. Wait {{ retryAfter }} seconds.</p>
  <p v-else-if="error" role="alert">{{ error.message }}</p>
</template>
```

After a code, the flow stops at `passkey-offer`. It calls `onSuccess` only once the person saves a passkey (`addPasskey()`) or declines (`skipPasskey()`). Render that step, or call `skipPasskey()` yourself. The flow skips the offer on its own in a browser without a passkey provider, and after a recovery `passkeyRequired` hides "Not now" ([The passkey offer](https://nuxt-backend.dev/docs/build/auth/sign-in#the-passkey-offer)).

### Keep passkey autofill

`useLoginFlow({ autofill: true })` offers saved passkeys in the email field's autofill, and `preferLastMethod: true` opens the page on the way this browser last signed in. The flow asks the browser only when the email field's `autocomplete` ends in `webauthn`:

```vue [app/pages/login.vue]
<template>
  <input v-model="email" type="email" autocomplete="username webauthn">
</template>
```

Mark the button of `lastMethod` (`'passkey'` or `'email-otp'`) "Last used". [Passkey autofill](https://nuxt-backend.dev/docs/build/auth/sign-in#passkey-autofill) has a complete page and what the person sees.

### Leave when already signed in

A person who is already signed in and opens the page should move on. Watch `isSignedIn` from `useAuth()`, and send them on from the `choose` and `request-code` steps only. During a code sign-in the person is signed in before the passkey offer, and leaving then would skip it. A passkey picked from autofill signs in on `request-code` and calls `onSuccess` too, so send the person on once, whichever comes first.

## Eject the form

When slots and parts aren't enough, copy the source into your app and own it.

```bash
npx nuxt-backend eject AuthForm
```

It writes `app/components/AuthForm.vue` and its CSS, stamped with the package version. Your copy wins, as a swapped part does. `npx nuxt-backend upgrade` later shows what changed in the package's version since the stamp, so you can carry fixes over by hand ([Eject a part, page or email](https://nuxt-backend.dev/docs/build/ui/customize/eject)).

## Verify

1. Sign out, open a page guarded with `definePageMeta({ auth: true })`, and check you land on your page with `?redirect=` set.
2. Sign in with a code: the page offers a passkey, then returns you to the guarded page.
3. Open the page with `?redirect=https://example.com`. After sign-in you land on your fallback, not on another site.
4. Sign out after a passkey sign-in and open the page again. The passkey button is marked "Last used", and the email field offers the passkey.

## If it fails

- **The module's page still renders.** Your page must sit at the exact path `pages.login` resolves to (`/login` by default). The dev server logs `App page at /login overrides the built-in login page` when it does.
- **The email field offers no passkey.** Its `autocomplete` does not end in `webauthn`, the flow was made without `autofill: true`, or the browser has no conditional mediation. The passkey button still works there.
- **A step shows nothing.** The page has no markup for it. Render every step of the table, or keep `<AuthForm>` and fill only the slots you change.

## Related

- [Sign users in](https://nuxt-backend.dev/docs/build/auth/sign-in): every field of `useLoginFlow`, and passkey autofill.
- [Protect pages and routes](https://nuxt-backend.dev/docs/build/auth/access/pages): the page rules that send people here.
- [Replace a page](https://nuxt-backend.dev/docs/build/ui/customize/parts#replace-a-page): moving and shadowing every packaged page.
- [Change copy and labels](https://nuxt-backend.dev/docs/build/ui/customize/labels): the words of `<AuthForm>`, without a slot.


## Sitemap

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