Docs/Get started

Your first dance

Install the library, teach the server the steps, then let the client run them.

  1. 01Install
  2. 02Server
  3. 03Client

01Install

Add Auth Dance to your project.

npm install auth-dance

02Teach the server

A choreography says which proof comes next.

const auth = createAuthDance({
  api: {
    choreography: sequence("email", "password"),
    components, channels, secret, storage,
  },
});

03Run the client

Use the same flow on the client.

const client = new AuthDanceClient({ baseUrl: "/api/auth" });
using dance = await client.signIn();

Fill in the server pieces

The compact example above names four application objects. components maps every choreography name to an implementation. channels delivers sendable prompts. secret signs tokens and encrypts flow state. storage keeps identities, sessions, temporary values, and rate-limit counters.

Set app.basePath when the routes should live below a prefix, then give the same prefix to AuthDanceClient.

const auth = createAuthDance({
  api: { choreography, components, channels, secret, storage },
  app: { basePath: "/api/auth" },
  info: { title: "Auth API", version: "1.0.0" },
});

Deno.serve(auth.fetch);

Answer every prompt kind

A flow alternates between server responses and client answers. For an input prompt, render the field described by dance.current and call submitPrompt(value). If that prompt is sendable, call sendPrompt() to ask its channel to deliver a value first.

For a choice prompt, render dance.choices and call choose(name). Keep answering until dance.done is true.

while (!dance.done) {
  if (dance.prompt?.kind === "choice") {
    await dance.choose(await chooseBranch(dance.choices));
  } else {
    if (dance.current?.sendable) await dance.sendPrompt();
    await dance.submitPrompt(await readValue(dance.current!));
  }
}

Continue with the real adapters

Use the next guides to configure a full server and client loop. Then choose the React bindings or drive the client directly. The factor and provider guides cover the built-in components, Deno KV, Cloudflare storage, and custom interfaces.

Try signing in with the demo beside this guide. It runs Auth Dance in your browser with temporary accounts and a local inbox. Choose another authentication flow to try email codes or passkeys.