# Code forms

> Six-digit code steps: confirm an email after sign-up, or a second factor at sign-in. SignInForm and SignUpForm show them for you.

Status: beta. Category: Auth.

```ts
import { VerifyEmailForm, TwoFactorForm } from '@glyphui/auth/ui'
```

Exports: `VerifyEmailForm`, `TwoFactorForm`, `secondFactorDescription`.

## Notes

- The input uses autocomplete="one-time-code", so phones offer the code from SMS or email.
- Resend waits 30 seconds between sends.
- A wrong code clears the input and shows the server’s message.
- TwoFactorForm words its step from method: "totp" (an authenticator app, the default), "email" (with the address) or "sms". SignInForm passes the method your server sends; override the text with twoFactor={{ title, description }}.

## VerifyEmailForm props

| Prop | Type | Default | Description |
|---|---|---|---|
| `email` (required) | `string` |  | The address the code was sent to. |
| `className` | `string` |  |  |
| `description` | `ReactNode` |  |  |
| `footer` | `ReactNode` |  |  |
| `headingLevel` | `HeadingLevel` |  | Heading level of the title. Default 1, for a page whose main content is the form. |
| `onBack` | `(() => void)` |  | Shows a "Use a different email" button. |
| `onSuccess` | `((session: AuthSession) => void)` |  |  |
| `title` | `ReactNode` | `Check your email` |  |

## Example: Verify an email

Paste or type the code from the toast; it submits on the sixth digit.

```tsx
import { AuthProvider, useAuth } from '@glyphui/auth'
import { memoryAdapter } from '@glyphui/auth/memory'
import { VerifyEmailForm } from '@glyphui/auth/ui'
import { Button, toast } from '@glyphui/ui'
import { useState } from 'react'

const adapter = memoryAdapter({
  latency: 400,
  onCode: ({ email, code }) => toast(`Email to ${email}`, { description: `Your code: ${code}` }),
})

function Demo() {
  const { signUp, signOut, user } = useAuth()
  const [email, setEmail] = useState<string | null>(null)
  if (user)
    return (
      <Button
        variant="outline"
        onClick={async () => {
          await signOut()
          setEmail(null)
        }}
      >
        Verified {user.email}. Start over
      </Button>
    )
  if (!email)
    return (
      <Button
        onClick={async () => {
          const address = `new.${Date.now()}@example.com`
          await signUp({ email: address, password: 'long password' })
          setEmail(address)
        }}
      >
        Create a demo account
      </Button>
    )
  return <VerifyEmailForm headingLevel={3} email={email} onBack={() => setEmail(null)} />
}

export default function Example() {
  return (
    <AuthProvider adapter={adapter} syncTabs={false}>
      <Demo />
    </AuthProvider>
  )
}
```

Live page: https://glyphui.xyz/components/verify-email-form
