# Auth pages

Opt in with `Panel.auth({...})` (or `Panel.configure({ auth: {...} })`). The pages
live behind the `@zerotal/admin/auth` subpath and sign people in with
[`@zerotal/auth`](/docs/authentication), which comes with the admin package. A
panel that leaves them off never loads them.

```ts fragment
import { Panel } from "@zerotal/admin";

Panel.auth({
  enabled: true,
  identifier: "email", // credential column
  remember: true,
  redirectTo: "/admin",
  authenticateWhen: (u) => (u as { active?: boolean }).active === true,

  // Optional — mounts the forgot/reset pages when provided:
  passwordReset: {
    sendResetLink: (email) => PasswordBroker.sendResetLink({ email }),
    reset: (input) => PasswordBroker.reset(input),
  },
  // Optional — mounts the verify page + profile banner when provided:
  emailVerification: {
    isVerified: (u) => (u as { email_verified_at?: unknown }).email_verified_at != null,
    resend: (u) =>
      (
        u as { sendEmailVerificationNotification(): Promise<void> }
      ).sendEmailVerificationNotification(),
  },
});
```

| Page                 | Route              | Uses                                            |
| -------------------- | ------------------ | ----------------------------------------------- |
| `LoginPage`          | `/login`           | `Auth.attempt` (+ remember, `authenticateWhen`) |
| `ProfilePage`        | `/profile`         | update details · change password · sign out     |
| `ForgotPasswordPage` | `/forgot-password` | `passwordReset.sendResetLink`                   |
| `ResetPasswordPage`  | `/reset-password`  | `passwordReset.reset`                           |
| `VerifyEmailPage`    | `/verify-email`    | `emailVerification.resend`                      |

Guest screens (login / forgot / reset) mount **outside** the panel guard so
unauthenticated users can reach them; profile / verify mount behind it
(override with `guestMiddleware` / `authMiddleware`). The 2FA **challenge** step is
left to your auth middleware — the rest of the flow ships here.

## Securing the panel

The panel is public until you set guard middleware. A typical setup:

```ts fragment
Panel.configure({ middleware: [AuthMiddleware, RequireRoleMiddleware.with("admin")] });
Panel.auth({ enabled: true }); // login lives outside that guard automatically
```

## Theming

By default the panel themes everything with Tailwind v4's **browser build**, loaded from
a pinned CDN URL, plus design tokens and a no-flash dark/light script — zero build step. The toggle in the
top bar flips `.dark` on `<html>` and persists the choice.

To ship a real build, point `theme.stylesheet` at your compiled CSS (the CDN is then
dropped) and reuse the exported theme CSS + tokens so your build matches the default look:

```ts
import { Panel, adminTailwindCss, adminTokensCss } from "@zerotal/admin";

Panel.configure({
  theme: {
    stylesheet: "/assets/admin.css", // your prebuilt Tailwind output
    // cdn: true,                      // keep both during migration
    // tokensCss: ":root { --primary: 270 90% 60%; }",  // override tokens
    // noFonts: true,                  // self-host Inter
  },
});
```

`adminTailwindCss()` returns the Tailwind v4 CSS that maps the tokens to utilities (the
same CSS the CDN reads). `adminTokensCss()` returns the `:root`/`.dark` custom properties,
plus the default border colour and the page background and text colour in `@layer base`,
so utilities such as `border-primary` still override them. Put both in your Tailwind v4
entry, after `@import "tailwindcss";`, so a compiled stylesheet renders identically.
`adminTailwindConfig()` is the same mapping as a Tailwind v3 config, for an app whose
build is still on v3.

## Types

| Type                          | What it is                                                                                                                                                              |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `AdminAuthConfig`             | Who may reach the panel and how they sign in.                                                                                                                           |
| `AdminAuthorizer`             | The check run before a page renders.                                                                                                                                    |
| `AuthRolesOptions`            | How panel access maps onto the app's roles.                                                                                                                             |
| `AdminThemeConfig`            | Panel theming.                                                                                                                                                          |
| `EnvironmentIndicatorOptions` | The banner naming which deployment you are looking at — worth setting, because the panel looks identical in staging and production and that is exactly when it matters. |

## Next steps

- [Admin overview](/docs/admin) — the guide's front page and the rest of the sections.
- [Reference](/docs/admin/references) — the full API surface in one table.
