Skip to Content

Auth Screens

Sign in and sign up with an email or phone code or OAuth, then verify the code.

Welcome back

or

New here?

By continuing you accept the terms.

import { AuthScreen } from "@dapplelight/signet-ui/screens/auth-screens"

const wait = (ms: number) => new Promise((r) => setTimeout(r, ms))
const providers = [{ id: "google", label: "Google" }]

export function AuthScreenDemo() {
  return (
    <AuthScreen
      providers={providers}
      onOAuth={() => wait(500)}
      onRequestCode={() => wait(500)}
      onVerify={async ({ code }) => {
        await wait(400)
        if (code !== "123456") throw new Error("That code is wrong. Try 123456.")
      }}
      footer={<p className="text-center text-xs text-neutral-500">By continuing you accept the terms.</p>}
    />
  )
}

Installation

npm i @dapplelight/signet-ui

Usage

import { AuthScreen, VerifyCodeScreen, SessionExpiredScreen } from "@dapplelight/signet-ui/screens/auth-screens"
import { sendCode, verify } from "./auth"

<AuthScreen onRequestCode={sendCode} onVerify={verify} />

Examples

AuthScreen

Welcome back

or

New here?

By continuing you accept the terms.

import { AuthScreen } from "@dapplelight/signet-ui/screens/auth-screens"

const wait = (ms: number) => new Promise((r) => setTimeout(r, ms))
const providers = [{ id: "google", label: "Google" }]

export function AuthScreenDemo() {
  return (
    <AuthScreen
      providers={providers}
      onOAuth={() => wait(500)}
      onRequestCode={() => wait(500)}
      onVerify={async ({ code }) => {
        await wait(400)
        if (code !== "123456") throw new Error("That code is wrong. Try 123456.")
      }}
      footer={<p className="text-center text-xs text-neutral-500">By continuing you accept the terms.</p>}
    />
  )
}

VerifyCodeScreen

Check your messages

Code sent to +91******3210

import { VerifyCodeScreen } from "@dapplelight/signet-ui/screens/auth-screens"

const wait = (ms: number) => new Promise((r) => setTimeout(r, ms))
const providers = [{ id: "google", label: "Google" }]

export function VerifyCodeScreenDemo() {
  return (
    <VerifyCodeScreen
      channel="phone"
      to="+91******3210"
      onBack={() => undefined}
      onVerify={async (code) => {
        await wait(400)
        if (code !== "123456") throw new Error("That code is wrong. Try 123456.")
      }}
      onResend={() => wait(300)}
      resendAfterSeconds={10}
    />
  )
}

SessionExpiredScreen

Session expired

Sign in again to pick up where you left off.

Sign-in requested 0 times

import { SessionExpiredScreen } from "@dapplelight/signet-ui/screens/auth-screens"
import { useState } from "react"

export function SessionExpiredScreenDemo() {
  const [clicks, setClicks] = useState(0)
  return (
    <div className="flex flex-col gap-2">
      <SessionExpiredScreen onSignIn={() => setClicks((n) => n + 1)} />
      <p className="text-center text-xs text-neutral-500">Sign-in requested {clicks} times</p>
    </div>
  )
}

CodeRequestForm

import { CodeRequestForm } from "@dapplelight/signet-ui/screens/auth-screens"

const wait = (ms: number) => new Promise((r) => setTimeout(r, ms))
const providers = [{ id: "google", label: "Google" }]

export function CodeRequestFormDemo() {
  return (
    <div className="w-full max-w-sm">
      <CodeRequestForm channel="email" onSubmit={() => wait(500)} />
    </div>
  )
}

VerifyCodeForm

import { VerifyCodeForm } from "@dapplelight/signet-ui/screens/auth-screens"

const wait = (ms: number) => new Promise((r) => setTimeout(r, ms))
const providers = [{ id: "google", label: "Google" }]

export function VerifyCodeFormDemo() {
  return (
    <div className="w-full max-w-sm">
      <VerifyCodeForm
        length={4}
        resendAfterSeconds={0}
        onVerify={async (code) => {
          await wait(300)
          if (code !== "1234") throw new Error("Try 1234.")
        }}
        onResend={() => wait(300)}
      />
    </div>
  )
}

OAuthButtons

import { OAuthButtons } from "@dapplelight/signet-ui/screens/auth-screens"

const wait = (ms: number) => new Promise((r) => setTimeout(r, ms))
const providers = [{ id: "google", label: "Google" }]

export function OAuthButtonsDemo() {
  return (
    <div className="w-full max-w-sm">
      <OAuthButtons
        providers={[
          { id: "google", label: "Google" },
          { id: "github", label: "GitHub" },
        ]}
        onSelect={() => wait(800)}
      />
    </div>
  )
}

AuthCard, AuthHeader, AuthDivider and AuthError

Join Acme

Create a workspace for your team.

or
import { Button } from "@dapplelight/signet-ui/components/button"
import { AuthCard, AuthDivider, AuthError, AuthHeader } from "@dapplelight/signet-ui/screens/auth-screens"

export function AuthPartsDemo() {
  return (
    <AuthCard>
      <AuthHeader title="Join Acme" description="Create a workspace for your team." />
      <Button size="lg">Continue with email</Button>
      <AuthDivider>or</AuthDivider>
      <Button size="lg" variant="outline">Use single sign-on</Button>
      <AuthError>That email is already registered.</AuthError>
    </AuthCard>
  )
}

API Reference

AuthScreen

PropTypeDefaultDescription
mode"sign-in" | "sign-up"—Controlled mode.
defaultMode"sign-in" | "sign-up""sign-in"Initial mode.
onModeChange(mode: AuthMode) => void—Called when the mode changes.
channelsreadonly AuthChannel[]["email", "phone"]Code channels to offer, in order. Empty for OAuth only.
channel"email" | "phone"—Selected channel, controlled.
defaultChannel"email" | "phone"first channelInitial channel.
onChannelChange(channel: AuthChannel) => void—Called when the channel changes.
onRequestCode(request: CodeRequest) => unknown—Send a code. Throw to show an error.
onVerify(request: CodeRequest & { code: string }) => unknown—Check the code and start the session.
providersreadonly OAuthProvider[][]OAuth buttons: id, label, icon.
onOAuth(provider: OAuthProvider, mode: AuthMode) => unknown—Start the OAuth flow.
logoReactNode—Shown above the title.
footerReactNode—Under the form: terms, a privacy link.
codeLengthnumber6Digits in the code.
resendAfterSecondsnumber30Seconds before Resend unlocks.
hideModeSwitchboolean—Hide the New here / Have an account switch.
labelsPartial<AuthLabels>—Every string, in English by default. Spread DEFAULT_AUTH_LABELS to translate.
classNamesPartial<Record<"card" | "header" | "oauth" | "divider" | "tabs" | "form" | "verify" | "footer", string>>—Classes per part.

VerifyCodeScreen

PropTypeDefaultDescription
channel"email" | "phone""email"Picks the icon and title.
tostring—Where the code went, shown as you pass it (mask it first).
onBack() => void—Shows a Change link back to the previous step.
logoReactNode—Replaces the icon.
onVerify(code: string) => unknown—Check the code.
onResend() => unknown—Resend the code.
lengthnumber6Digits in the code.
resendAfterSecondsnumber30Seconds before Resend unlocks; 0 unlocks at once.
labelsPartial<AuthLabels>—Every string, in English by default. Spread DEFAULT_AUTH_LABELS to translate.

SessionExpiredScreen

PropTypeDefaultDescription
onSignIn() => unknown—Called by the Sign in again button.
logoReactNode—Replaces the clock icon.
labelsPartial<AuthLabels>—Every string, in English by default. Spread DEFAULT_AUTH_LABELS to translate.

CodeRequestForm

PropTypeDefaultDescription
channel"email" | "phone"—Which field to show.
onSubmit(to: string) => unknown—Send the code.
defaultValuestring—Initial address.
labelsPartial<AuthLabels>—Every string, in English by default. Spread DEFAULT_AUTH_LABELS to translate.

VerifyCodeForm

PropTypeDefaultDescription
onVerify(code: string) => unknown—Called when the code is full or submitted.
onResend() => unknown—Resend the code.
lengthnumber6Digits in the code.
resendAfterSecondsnumber30Seconds before Resend unlocks.
labelsPartial<AuthLabels>—Every string, in English by default. Spread DEFAULT_AUTH_LABELS to translate.

OAuthButtons

PropTypeDefaultDescription
providersreadonly OAuthProvider[]—One button each.
onSelect(provider: OAuthProvider) => unknown—May redirect away; a returned Promise keeps the button pending.
labelsPartial<AuthLabels>—Every string, in English by default. Spread DEFAULT_AUTH_LABELS to translate.

AuthHeader

PropTypeDefaultDescription
titleReactNode—The heading.
descriptionReactNode—Text under the heading.
iconReactNode—An icon or your logo, above the title.

AuthCard, AuthDivider, AuthError

PropTypeDefaultDescription
classNamestring—Merged over the defaults. AuthCard also takes render to swap its element.