Saved login

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

Saved login

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.

On the web or runtimes below 1.8, the save/clear commands are skipped — check result.skipped and result.reason. To check support up front, read bdk.getDeviceInfo()?.smartLoginAvailable.

import { createBdkNative } from "@bdk/native/browser";

export const bdk = createBdkNative();

Save credentials after login

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

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

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

if (result.skipped) {
  // Runtime is below 1.8 or not native — Smart Login storage unavailable.
  console.warn("Smart Login not available:", result.reason);
}

Clear saved credentials

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

async function logout() {
  await bdk.auth.clearCredentials();
  // ...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.

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();