{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "auth-05",
  "description": "One form to sign in or sign up, with Google, X and GitHub on one row, a password you can show, and a switch at the bottom that unfolds the sign-up fields and a password strength meter.",
  "registryDependencies": [
    "button",
    "field",
    "input",
    "https://www.dashboardblocks.com/r/radix/auth.json",
    "https://www.dashboardblocks.com/r/radix/brand-logos.json",
    "https://www.dashboardblocks.com/r/radix/forms.json",
    "https://www.dashboardblocks.com/r/radix/rolling-text.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/auth/auth-05.tsx",
      "content": "'use client'\n\nimport {\n  AuthDivider,\n  AuthIcon,\n  AuthLayout,\n  type AuthProvider,\n  AuthProviderButtons,\n  AuthReveal,\n  AuthSwitch,\n  PasswordInput,\n  PasswordStrength,\n  getMissingPasswordRules,\n} from '@/registry/components/dashboardblocks/auth'\nimport {\n  GitHubLogo,\n  GoogleLogo,\n  XLogo,\n} from '@/registry/components/dashboardblocks/brand-logos'\nimport {\n  type FormErrors,\n  useSimpleForm,\n} from '@/registry/components/dashboardblocks/forms'\nimport { RollingText } from '@/registry/components/dashboardblocks/rolling-text'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport {\n  type FormEvent,\n  type ReactNode,\n  startTransition,\n  useEffect,\n  useRef,\n  useState,\n} from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Field, FieldError, FieldLabel } from '@/components/ui/field'\nimport { Input } from '@/components/ui/input'\n\ntype Auth5Mode = 'sign-in' | 'sign-up'\n\ntype Auth5Field = 'email' | 'name' | 'password'\n\n/** Refuse with a sentence for the whole form, such as a wrong password, or one for each field. */\ntype Auth5Result = {\n  errors?: Partial<Record<Auth5Field, string>>\n  message?: string\n  status: 'error'\n} | void\n\ninterface Auth5Props {\n  defaultMode?: Auth5Mode\n  focusOnMount?: boolean\n  /** Where \"Forgot password?\" leads, such as a page with Auth 6. Leave it out to hide the link. */\n  forgotPasswordHref?: string\n  /** Send the person to the provider. A throw shows that it couldn't be reached. */\n  onProvider?: (id: string) => void | Promise<void>\n  /** Check the email and password again on the server; this form only checks they're filled in. */\n  onSignIn?: (values: { email: string; password: string }) => Promise<Auth5Result>\n  /** Check every field again on the server, the password rules included. */\n  onSignUp?: (values: {\n    email: string\n    name: string\n    password: string\n  }) => Promise<Auth5Result>\n  /** Named in \"New to Acme Analytics?\". */\n  productName: string\n  providers?: AuthProvider[]\n  /** One sentence about signing up, such as a free trial. */\n  signUpNote?: string\n  /** Shown under the sign-up button, such as links to the terms. */\n  terms?: ReactNode\n}\n\nconst exampleProps: Auth5Props = {\n  forgotPasswordHref: '#forgot-password',\n  onSignIn: async ({ password }) => {\n    await new Promise((resolve) => setTimeout(resolve, 700))\n    if (password !== 'Northwind1')\n      return {\n        message:\n          'That email and password don’t match. Try again, or reset your password.',\n        status: 'error',\n      }\n  },\n  onSignUp: async () => {\n    await new Promise((resolve) => setTimeout(resolve, 900))\n  },\n  productName: 'Acme Analytics',\n  providers: [\n    { icon: <GoogleLogo />, id: 'google', name: 'Google' },\n    { icon: <XLogo />, id: 'x', name: 'X' },\n    { icon: <GitHubLogo />, id: 'github', name: 'GitHub' },\n  ],\n  signUpNote: 'Free for 14 days. No card needed.',\n  terms: (\n    <>\n      By creating an account you agree to the{' '}\n      <a href='#terms' className='text-foreground underline underline-offset-4'>\n        Terms\n      </a>{' '}\n      and the{' '}\n      <a href='#privacy' className='text-foreground underline underline-offset-4'>\n        Privacy Policy\n      </a>\n      .\n    </>\n  ),\n}\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\ntype Values = Record<Auth5Field, string>\n\nconst Auth5 = (props: Auth5Props) => {\n  const {\n    defaultMode = 'sign-in',\n    focusOnMount = false,\n    forgotPasswordHref,\n    onProvider,\n    onSignIn,\n    onSignUp,\n    productName,\n    providers = [],\n    signUpNote,\n    terms,\n  } = props\n  const [mode, setMode] = useState(defaultMode)\n  const [message, setMessage] = useState<string | null>(null)\n  const [done, setDone] = useState(false)\n  const refused = useRef(false)\n  const focusedMode = useRef<Auth5Mode | null>(focusOnMount ? null : defaultMode)\n  const signUp = mode === 'sign-up'\n\n  const form = useSimpleForm<Values>({\n    defaultValues: { email: '', name: '', password: '' },\n    onSubmit: async ({ email, name, password }) => {\n      refused.current = false\n      const values = { email: email.trim().toLowerCase(), password }\n      const result = signUp\n        ? await onSignUp?.({ ...values, name: name.trim() })\n        : await onSignIn?.(values)\n      if (result?.status !== 'error') return\n      refused.current = true\n      startTransition(() => setMessage(result.message ?? null))\n      return result.errors\n    },\n    validate: ({ email, name, password }): FormErrors<Values> => ({\n      email: !email.trim()\n        ? 'Enter your email address.'\n        : EMAIL.test(email.trim())\n          ? undefined\n          : 'Enter an email address like name@company.com.',\n      name: signUp && !name.trim() ? 'Enter your name.' : undefined,\n      password: !password\n        ? signUp\n          ? 'Choose a password.'\n          : 'Enter your password.'\n        : signUp && getMissingPasswordRules(password).length\n          ? 'Not strong enough yet.'\n          : undefined,\n    }),\n  })\n\n  useEffect(() => {\n    if (mode === focusedMode.current) return\n    focusedMode.current = mode\n    document.getElementById(form.getId(mode === 'sign-up' ? 'name' : 'email'))?.focus()\n  }, [form, mode])\n\n  const submit = async (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault()\n    if (form.isSubmitting) return\n    setMessage(null)\n    try {\n      const saved = await form.submit(event)\n      if (saved && !refused.current) startTransition(() => setDone(true))\n    } catch {\n      startTransition(() =>\n        setMessage(\n          signUp\n            ? 'We couldn’t create your account. Check your connection and try again.'\n            : 'We couldn’t sign you in. Check your connection and try again.',\n        ),\n      )\n    }\n  }\n\n  const switchMode = () => {\n    setMode(signUp ? 'sign-in' : 'sign-up')\n    setMessage(null)\n  }\n\n  const pending = form.isSubmitting\n  const strengthId = `${form.getId('password')}-strength`\n\n  return (\n    <AuthLayout\n      media={\n        done ? (\n          <AuthIcon tone='done' />\n        ) : (\n          <AuthIcon>\n            <IconPlaceholder\n              lucide='LogInIcon'\n              tabler='IconLogin'\n              hugeicons='Login03Icon'\n              phosphor='SignInIcon'\n              remixicon='RiLoginBoxLine'\n              aria-hidden\n            />\n          </AuthIcon>\n        )\n      }\n      title={\n        <RollingText\n          text={\n            done\n              ? signUp\n                ? 'Account created'\n                : 'You’re signed in'\n              : signUp\n                ? 'Create your account'\n                : 'Welcome back'\n          }\n          wrap\n        />\n      }\n      description={\n        <RollingText\n          text={\n            done\n              ? 'Taking you to your workspace…'\n              : signUp\n                ? (signUpNote ?? 'It takes a minute.')\n                : 'Sign in to pick up where you left off.'\n          }\n          wrap\n        />\n      }\n    >\n      <AuthReveal open={!done}>\n        <div className='flex flex-col gap-6'>\n          <form\n            method='post'\n            noValidate\n            onSubmit={(event) => void submit(event)}\n            className='flex flex-col'\n          >\n            <AuthReveal open={signUp} className='pb-4'>\n              <Field data-invalid={form.errors.name ? true : undefined}>\n                <FieldLabel htmlFor={form.getId('name')}>Name</FieldLabel>\n                <Input autoComplete='name' disabled={pending} {...form.field('name')} />\n                <FieldError {...form.error('name')} />\n              </Field>\n            </AuthReveal>\n            <div className='flex flex-col gap-4'>\n              <Field data-invalid={form.errors.email ? true : undefined}>\n                <FieldLabel htmlFor={form.getId('email')}>Email</FieldLabel>\n                <Input\n                  type='email'\n                  autoComplete='email'\n                  disabled={pending}\n                  {...form.field('email')}\n                />\n                <FieldError {...form.error('email')} />\n              </Field>\n              <Field data-invalid={form.errors.password ? true : undefined}>\n                <div className='flex items-baseline justify-between gap-3'>\n                  <FieldLabel htmlFor={form.getId('password')}>Password</FieldLabel>\n                  {forgotPasswordHref && (\n                    <a\n                      href={forgotPasswordHref}\n                      inert={signUp}\n                      className='text-muted-foreground hover:text-foreground text-sm underline-offset-4 transition-opacity duration-200 hover:underline data-[hidden]:opacity-0'\n                      data-hidden={signUp || undefined}\n                    >\n                      Forgot password?\n                    </a>\n                  )}\n                </div>\n                <PasswordInput\n                  autoComplete={signUp ? 'new-password' : 'current-password'}\n                  disabled={pending}\n                  {...form.field('password')}\n                  aria-describedby={\n                    [signUp && strengthId, form.field('password')['aria-describedby']]\n                      .filter(Boolean)\n                      .join(' ') || undefined\n                  }\n                />\n                <FieldError {...form.error('password')} />\n              </Field>\n            </div>\n            <AuthReveal open={signUp} className='pt-3'>\n              <PasswordStrength id={strengthId} password={form.values.password} />\n            </AuthReveal>\n            {message && (\n              <p role='alert' className='text-destructive mt-4 text-sm text-pretty'>\n                {message}\n              </p>\n            )}\n            <Button\n              type='submit'\n              size='lg'\n              className='mt-5 aria-disabled:opacity-50'\n              aria-disabled={pending || undefined}\n            >\n              <RollingText\n                text={\n                  pending\n                    ? signUp\n                      ? 'Creating account'\n                      : 'Signing in'\n                    : signUp\n                      ? 'Create account'\n                      : 'Sign in'\n                }\n              />\n            </Button>\n            {terms && (\n              <AuthReveal open={signUp} className='pt-3'>\n                <p className='text-muted-foreground text-xs text-pretty'>{terms}</p>\n              </AuthReveal>\n            )}\n          </form>\n          {providers.length > 0 && (\n            <>\n              <AuthDivider />\n              <AuthProviderButtons\n                providers={providers}\n                disabled={pending}\n                onSelect={onProvider}\n              />\n            </>\n          )}\n          <AuthSwitch\n            title={signUp ? 'Already have an account?' : `New to ${productName}?`}\n            description={\n              signUp\n                ? providers.length\n                  ? 'Sign in with your email or an account you already use.'\n                  : 'Sign in with your email.'\n                : signUpNote\n                  ? `Create an account. ${signUpNote}`\n                  : 'Create an account.'\n            }\n            onClick={switchMode}\n          />\n        </div>\n      </AuthReveal>\n      <p role='status' className='sr-only'>\n        {done ? (signUp ? 'Account created' : 'You’re signed in') : ''}\n      </p>\n    </AuthLayout>\n  )\n}\n\nexport { Auth5, exampleProps as auth5ExampleProps, type Auth5Props, type Auth5Result }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/auth/auth-05.tsx"
    }
  ],
  "meta": {
    "shows": "One form to sign in or sign up, with Google, X and GitHub on one row, a password you can show, and a switch at the bottom that unfolds the sign-up fields and a password strength meter.",
    "size": "page",
    "usedWith": [
      "auth-06",
      "auth-04"
    ],
    "component": "Auth5",
    "props": "{ defaultMode?: \"sign-in\" | \"sign-up\"; focusOnMount?: boolean; forgotPasswordHref?: string; onProvider?: (id: string) => void | Promise<void>; onSignIn?: (values: { email: string; password: string }) => Promise<void | { errors?: { name?: string; email?: string; password?: string }; message?: string; status: \"error\" }>; onSignUp?: (values: { email: string; name: string; password: string }) => Promise<void | { errors?: { name?: string; email?: string; password?: string }; message?: string; status: \"error\" }>; productName: string; providers?: { icon: ReactNode; id: string; name: string }[]; signUpNote?: string; terms?: ReactNode }"
  },
  "type": "registry:component"
}
