Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tkhq/sdk/llms.txt

Use this file to discover all available pages before exploring further.

Turnkey supports multiple authentication methods out of the box. Each method creates or retrieves a sub-organization for the user, then issues a session token used to sign subsequent API requests. Supported methods:
  • Passkeys — WebAuthn-based biometric or hardware key authentication
  • Email OTP — one-time passcode sent to the user’s email address
  • Phone OTP — one-time passcode sent via SMS
  • OAuth — social login via Google, Apple, Facebook, X (Twitter), or Discord
When you use the Auth Proxy (authProxyConfigId), Turnkey’s managed backend handles credential validation, sub-organization creation, and session issuance. You do not need to run your own server for most authentication flows.

Quick authentication

The fastest way to add auth to a React app is handleLogin from the useTurnkey hook. It opens a modal with every method you have enabled in your Auth Proxy Config.
components/LoginButton.tsx
"use client";

import { useTurnkey } from "@turnkey/react-wallet-kit";

export function LoginButton() {
  const { handleLogin } = useTurnkey();

  return <button onClick={handleLogin}>Log in / Sign up</button>;
}

Authentication methods

Passkeys use the WebAuthn API to authenticate users with biometrics or a hardware security key. Turnkey creates a sub-organization for each user and registers the passkey as an authenticator.

Enable passkeys

Set passkeyAuthEnabled: true in TurnkeyProviderConfig.auth.methods:
app/providers.tsx
"use client";

import { TurnkeyProvider, TurnkeyProviderConfig } from "@turnkey/react-wallet-kit";

const turnkeyConfig: TurnkeyProviderConfig = {
  organizationId: process.env.NEXT_PUBLIC_ORGANIZATION_ID!,
  authProxyConfigId: process.env.NEXT_PUBLIC_AUTH_PROXY_CONFIG_ID!,
  auth: {
    methods: {
      passkeyAuthEnabled: true,
    },
  },
};

export function Providers({ children }: { children: React.ReactNode }) {
  return <TurnkeyProvider config={turnkeyConfig}>{children}</TurnkeyProvider>;
}

Add a passkey to an existing account

Once logged in, users can register additional passkeys using handleAddPasskey:
components/AddPasskey.tsx
"use client";

import { useTurnkey } from "@turnkey/react-wallet-kit";

export function AddPasskeyButton() {
  const { handleAddPasskey } = useTurnkey();

  return (
    <button
      onClick={() =>
        handleAddPasskey({
          displayName: "My device passkey",
          successPageDuration: 2000,
        })
      }
    >
      Add passkey
    </button>
  );
}

Session management

After a successful authentication, the SDK stores a session token and exposes it through the useTurnkey hook:
components/SessionStatus.tsx
"use client";

import { useTurnkey } from "@turnkey/react-wallet-kit";

export function SessionStatus() {
  const { session, authState } = useTurnkey();

  if (authState === "unauthenticated") {
    return <p>Not logged in.</p>;
  }

  return <p>Session expires: {session?.expiry}</p>;
}
Session expiration is controlled by auth.sessionExpirationSeconds in your TurnkeyProviderConfig (default: 900 seconds / 15 minutes). When using the Auth Proxy, configure this value through the Turnkey dashboard instead. To handle session events, add lifecycle callbacks to TurnkeyProvider:
app/providers.tsx
<TurnkeyProvider
  config={turnkeyConfig}
  callbacks={{
    onAuthenticationSuccess: ({ session, action, method, identifier }) => {
      console.log("Authenticated via", method, "as", identifier);
    },
    beforeSessionExpiry: ({ sessionKey }) => {
      console.log("Session expiring soon:", sessionKey);
    },
    onSessionExpired: ({ sessionKey }) => {
      console.log("Session expired:", sessionKey);
    },
    onError: (error) => console.error("Turnkey error:", error),
  }}
>
  {children}
</TurnkeyProvider>

Server-side session validation

Use TurnkeyServerClient from @turnkey/sdk-server to verify sessions or perform privileged operations on the server:
server/validate.ts
import { TurnkeyServerClient } from "@turnkey/sdk-server";

const client = new TurnkeyServerClient({
  stamper: myStamper, // ApiKeyStamper or equivalent
  apiBaseUrl: "https://api.turnkey.com",
  organizationId: process.env.TURNKEY_ORGANIZATION_ID!,
});

// Use the client to call any Turnkey API method
const user = await client.getUser({
  organizationId: suborgsOrganizationId,
  userId: sessionUserId,
});

Auth method configuration reference

All authentication options are set under auth.methods in TurnkeyProviderConfig:
OptionTypeDescription
emailOtpAuthEnabledbooleanEnable email OTP login
smsOtpAuthEnabledbooleanEnable SMS OTP login
passkeyAuthEnabledbooleanEnable passkey (WebAuthn) login
walletAuthEnabledbooleanEnable wallet-based login
googleOauthEnabledbooleanEnable Google OAuth
appleOauthEnabledbooleanEnable Apple OAuth
facebookOauthEnabledbooleanEnable Facebook OAuth
xOauthEnabledbooleanEnable X (Twitter) OAuth
discordOauthEnabledbooleanEnable Discord OAuth