> ## Documentation Index
> Fetch the complete documentation index at: https://docs.turnkey.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a user passkey session

> A passkey session is an expiring session enabled by an initial passkey authentication. You could think of this as a "lightning mode" of sorts: creating a passkey session allows users to authenticate subsequent requests touch-free. Under the hood, this is powered by our [indexedDbStamper](/sdks/advanced/indexed-db-stamper). These sessions are enabled by creating a short-lived embedded API key in the browser, stored in localStorage, and cryptographically scoped to a public key generated by IndexedDB.

> ⚠️ **This example is outdated !**<br />
> Head over to [SDK Reference](https://docs.turnkey.com/generated-docs/formatted/react-wallet-kit/client-context-type-login-with-passkey) for the updated packages.

By calling `loginWithPasskey()`, the SDK stores the session and active client in localStorage. The signing key material remains securely stored in the browser’s IndexedDB and is never extractable. Turnkey uses this public key to scope and encrypt the session to the appropriate user.

## Steps using `@turnkey/sdk-react`

This process is made seamless by leveraging our [React package](/sdks/react). Read on for a non-React implementation below.

<Steps>
  <Step title="Initialize the React Provider">
    ```js theme={"system"}
    import { TurnkeyProvider } from "@turnkey/sdk-react";

    const turnkeyConfig = {
      apiBaseUrl: "https://api.turnkey.com",
      defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID,
      rpId: process.env.RPID,
    };

    ...

    <div className="App">
      <TurnkeyProvider config={turnkeyConfig}>
        {/* Your app components */}
      </TurnkeyProvider>
    </div>
    ```
  </Step>

  <Step title="Login with a Passkey and Create a Session">
    ```js theme={"system"}
    import { useTurnkey } from "@turnkey/sdk-react";

    const { passkeyClient, indexedDbClient } = useTurnkey();

    await indexedDbClient.init();
    const publicKey = await indexedDbClient.getPublicKey();

    await passkeyClient.loginWithPasskey({
      publicKey,
      sessionType: "SESSION_TYPE_READ_WRITE", // or "SESSION_TYPE_READ_ONLY"
      expirationSeconds: 900,
    });
    ```
  </Step>

  <Step title="Use the session to make requests">
    ```js theme={"system"}
    const { getActiveClient } = useTurnkey();
    const client = await getActiveClient();

    const whoami = await client.getWhoami({
      organizationId: <your-org-id>,
    });
    ```

    `getActiveClient()` returns the currently active client (e.g. IndexedDb-backed), refreshing automatically if needed.
  </Step>
</Steps>

## Alternative steps (non-React)

<Steps>
  <Step title="Initialize the Passkey and IndexedDB Clients">
    ```js theme={"system"}
    import { Turnkey } from "@turnkey/sdk-browser";

    const turnkey = new Turnkey({
      apiBaseUrl: "https://api.turnkey.com",
      defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID,
    });

    const passkeyClient = turnkey.passkeyClient();
    const indexedDbClient = turnkey.indexedDbClient();

    await indexedDbClient.init();
    ```
  </Step>

  <Step title="Login with a Passkey and Create a Session">
    ```js theme={"system"}
    const publicKey = await indexedDbClient.getPublicKey();

    await passkeyClient.loginWithPasskey({
      publicKey,
      sessionType: "SESSION_TYPE_READ_WRITE", // or "SESSION_TYPE_READ_ONLY"
      expirationSeconds: 900,
    });
    ```
  </Step>

  <Step title="Use the session to make requests">
    ```js theme={"system"}
    const whoami = await turnkey.getWhoami({
      organizationId: <your-org-id>,
    });
    ```

    Once `loginWithPasskey` completes, the session is stored in localStorage and all requests are signed using the IndexedDb-backed keypair.
  </Step>
</Steps>
