Auth Dialog
An opinionated sign-in dialog with OAuth provider buttons, a passkey option, and a unified email continue flow.
Installation
npx shadcn@latest add https://ui.mattdowney.com/r/auth-dialog.jsonUsage
import { AuthDialog } from "@/components/ui/auth-dialog"Examples
Default
All four providers, passkey, and magic-link email in the unified continue flow. Handlers return promises, so the dialog runs the pending choreography and closes on resolve via controlled open. The footer slot carries the terms line.
Password Mode
emailMode="password" adds an inline password field and guarantees password in the continue payload. Also shows trimming the surface: one provider, no passkey.
Pending State
While a handler's promise is in flight, the clicked method shows a spinner (after a 200ms grace, so fast responses never flash) and every other method disables. Escape and the close button keep working.
Error Handling
A rejected promise un-pends the dialog and announces the rejection's message under the header. The message region is collapsed until it has something to say, so the panel grows to make room and shrinks again on the next attempt.
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| providersAuthDialog | ("google" | "github" | "microsoft" | "apple")[] | all four | Which OAuth provider buttons to render, in array order. Pass [] to render none. |
| showPasskeyAuthDialog | boolean | true | Renders the passkey button in the method stack. |
| showEmailAuthDialog | boolean | true | Renders the email form (and the separator when methods render above it). |
| emailModeAuthDialog | "magic-link" | "password" | "magic-link" | Magic link collects email only. Password adds an inline password field and types password as required in the continue payload. |
| submitLabelAuthDialog | React.ReactNode | "Send magic link" / "Continue" | Overrides the email submit button's label. The default follows emailMode, because the two modes promise different things: in magic-link the button does not sign you in, it sends a mail and the next screen is your inbox, so it reads "Send magic link"; in password the submit really does sign you in, so it reads "Continue". Pass anything to override either, e.g. submitLabel="Continue" to keep the generic wording. |
| onProviderContinueAuthDialog | (provider) => void | Promise<void> | None | Called with the clicked provider. Return a promise to get pending and error handling; return void for an immediate redirect. |
| onPasskeyContinueAuthDialog | () => void | Promise<void> | None | Called when the passkey button is clicked. Same promise contract. |
| onEmailContinueAuthDialog | ({ email, password? }) => void | Promise<void> | None | Called on a valid email submit (native validation gates it). The payload is discriminated by emailMode. |
| titleAuthDialog | ReactNode | "Sign in" | Dialog title. |
| descriptionAuthDialog | ReactNode | "Choose how you want to continue" | Dialog description under the title. |
| triggerAuthDialog | ReactNode | None | Rendered through DialogTrigger. Omit when driving open externally. |
| footerAuthDialog | ReactNode | None | Terms/privacy copy pinned at the bottom in small muted text. |
| errorAuthDialog | string | null | None | An error you already know about, shown where a rejected handler's message goes. See Auth Form. |
| forgotPasswordAuthDialog | ReactNode | None | A link beside the Password label in password mode. See Auth Form. |
| openAuthDialog | boolean | None | Controlled open state, forwarded to the underlying Dialog. Pair with onOpenChange. |
| onOpenChangeAuthDialog | (open: boolean) => void | None | Called when the open state changes. |
| defaultOpenAuthDialog | boolean | false | Uncontrolled initial open state. |
providersAuthDialog("google" | "github" | "microsoft" | "apple")[] = all fourWhich OAuth provider buttons to render, in array order. Pass [] to render none. |
| showPasskeyAuthDialogboolean = trueRenders the passkey button in the method stack. |
| showEmailAuthDialogboolean = trueRenders the email form (and the separator when methods render above it). |
emailModeAuthDialog"magic-link" | "password" = "magic-link"Magic link collects email only. Password adds an inline password field and types password as required in the continue payload. |
submitLabelAuthDialogReact.ReactNode = "Send magic link" / "Continue"Overrides the email submit button's label. The default follows emailMode, because the two modes promise different things: in magic-link the button does not sign you in, it sends a mail and the next screen is your inbox, so it reads "Send magic link"; in password the submit really does sign you in, so it reads "Continue". Pass anything to override either, e.g. submitLabel="Continue" to keep the generic wording. |
| onProviderContinueAuthDialog(provider) => void | Promise<void>Called with the clicked provider. Return a promise to get pending and error handling; return void for an immediate redirect. |
| onPasskeyContinueAuthDialog() => void | Promise<void>Called when the passkey button is clicked. Same promise contract. |
onEmailContinueAuthDialog({ email, password? }) => void | Promise<void>Called on a valid email submit (native validation gates it). The payload is discriminated by emailMode. |
| titleAuthDialogReactNode = "Sign in"Dialog title. |
| descriptionAuthDialogReactNode = "Choose how you want to continue"Dialog description under the title. |
triggerAuthDialogReactNodeRendered through DialogTrigger. Omit when driving open externally. |
| footerAuthDialogReactNodeTerms/privacy copy pinned at the bottom in small muted text. |
| errorAuthDialogstring | nullAn error you already know about, shown where a rejected handler's message goes. See Auth Form. |
forgotPasswordAuthDialogReactNodeA link beside the Password label in password mode. See Auth Form. |
openAuthDialogbooleanControlled open state, forwarded to the underlying Dialog. Pair with onOpenChange. |
| onOpenChangeAuthDialog(open: boolean) => voidCalled when the open state changes. |
| defaultOpenAuthDialogboolean = falseUncontrolled initial open state. |
"use client"
import * as React from "react"
import { cn } from "@/registry/lib/utils"
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/registry/ui/dialog"
import { AuthForm, type AuthFormEmbed, type AuthFormOptions } from "@/registry/ui/auth-form"
// AUTH_PROVIDERS is a plain value, but a client module's exports are still
// client references under RSC, so it lives in a directive-free sibling
// module along with the type it derives. See auth-providers.ts.
import { AUTH_PROVIDERS, type AuthProvider } from "@/registry/ui/auth-providers"
// The Dialog's own parts, so its title labels the popup and its header keeps
// the close-button inset. Module scope: a new object each render would be a
// new set of component types, and React would remount the form's header.
const dialogParts: AuthFormEmbed = {
slot: "auth-dialog",
Header: DialogHeader,
Title: DialogTitle,
Description: DialogDescription,
}
type AuthDialogProps = Pick<
React.ComponentProps<typeof Dialog>,
"open" | "defaultOpen" | "onOpenChange"
> &
Omit<React.ComponentProps<typeof DialogContent>, "children" | "title"> &
AuthFormOptions & {
/** Rendered through DialogTrigger. Omit when driving `open` externally. */
trigger?: React.ReactNode
}
// @use-when a sign-in or sign-up dialog offering provider buttons, a passkey,
// or an email form.
function AuthDialog({
providers,
showPasskey,
showEmail,
emailMode,
onProviderContinue,
onPasskeyContinue,
onEmailContinue,
title,
description,
submitLabel,
footer,
error,
forgotPassword,
trigger,
open,
defaultOpen,
onOpenChange,
className,
...props
}: AuthDialogProps) {
// Re-joined as one object because `emailMode` and `onEmailContinue` are a
// discriminated pair, and TypeScript cannot re-pair them from two loose
// destructured names.
const email = { emailMode, onEmailContinue } as AuthFormOptions
return (
<Dialog open={open} defaultOpen={defaultOpen} onOpenChange={onOpenChange}>
{trigger != null && <DialogTrigger render={trigger as React.ReactElement} />}
<DialogContent
data-slot="auth-dialog"
className={cn("sm:max-w-sm", className)}
{...props}
>
{/* The whole body is AuthForm, embedded: its blocks land as direct
children of the popup's grid, which spaces them, so the dialog and
the page form cannot drift apart. */}
<AuthForm
embed={dialogParts}
providers={providers}
showPasskey={showPasskey}
showEmail={showEmail}
{...email}
onProviderContinue={onProviderContinue}
onPasskeyContinue={onPasskeyContinue}
title={title}
description={description}
submitLabel={submitLabel}
footer={footer}
error={error}
forgotPassword={forgotPassword}
/>
</DialogContent>
</Dialog>
)
}
// rsc-reexport: AUTH_PROVIDERS -> auth-providers
// kept for existing client call sites; server callers import the sibling
export { AuthDialog, AUTH_PROVIDERS }
export type { AuthDialogProps, AuthProvider }