Saved login

Save, restore, and clear a user's email and password so returning users skip the login form.

Saved login

Examples reuse the single browser client from Set up the client. Adjust the ~/lib/bdk import to your app’s path; do not create a client in each component or handler.

Let returning users sign back in without re-typing their credentials. Methods live on bdk.auth, with one event for the response.

  • auth.updateCredentials({ email, password }) — save credentials after login.
  • auth.clearCredentials() — wipe saved credentials, e.g. on logout.
  • auth.loginViaCredentials() — request saved credentials; they arrive on the smartLoginCredentials event.

loginViaCredentials() doesn't return the credentials — read them from the smartLoginCredentials event.

Outside the native app the save/clear commands don't run. Branch on !result.triggered. To check support up front, read bdk.getDeviceInfo()?.smartLoginAvailable.

import { bdk } from "~/lib/bdk";

Save credentials after login

Call this right after a user authenticates so they sign in instantly next time.

Wrap the call in try/catch and report whether it completed. Do not treat a failed credential operation as a successful sign-in or sign-out.

Only save after you've verified the login is real.

The examples use your app’s showActionUnavailable() UI handler.

try {
  const result = await bdk.auth.updateCredentials({
    email: "ada@example.com",
    password: "hunter2"
  });

  if (!result.triggered) {
    // Not running in the native app — Smart Login storage unavailable.
    console.warn("Smart Login not available:", result.reason);
  }
} catch {
  showActionUnavailable();
}

Clear saved credentials

Call this on logout to forget the saved login. Takes no arguments.

Wrap the call in try/catch and report whether it completed. Do not treat a failed credential operation as a successful sign-in or sign-out.

The examples use your app’s showActionUnavailable() UI handler.

async function logout() {
  try {
    await bdk.auth.clearCredentials();
  } catch {
    showActionUnavailable();
  }
  // ...continue your app's sign-out flow
}

Log in with saved credentials

On a returning visit, request the saved credentials. They arrive on the smartLoginCredentials event as { email: string | null; password: string | null }. If either field is null, nothing usable is saved — fall back to your login screen.

Register your smartLoginCredentials listener with bdk.on(...) before you call loginViaCredentials(), or you'll miss the response.

The examples use your app’s showActionUnavailable() UI handler.

const off = bdk.on("smartLoginCredentials", ({ email, password }) => {
  if (email && password) {
    // Auto-fill your form or call your sign-in endpoint.
    signIn(email, password);
  } else {
    // Nothing saved (or values failed validation) — show the login screen.
    showLoginForm();
  }
});

await bdk.auth.loginViaCredentials();

// Later, when the screen unmounts:
off();

See it running in the live demo, or every native feature with its demo on thebdk.com.