starti.app
How-to Guides

Biometric Login

Use Face ID and fingerprint to save and retrieve user credentials securely

Biometric Login

Use biometrics (Face ID / fingerprint) to let users log in without typing their credentials each time. The SDK can save, retrieve, and manage username/password pairs secured by biometric authentication.

Prerequisites

  • The starti.app SDK is installed and initialized
  • The device supports biometric authentication (Face ID or fingerprint)

Option A: Manual credential flow

Save and retrieve credentials directly with biometric protection.

Save credentials

await startiapp.Biometrics.setUsernameAndPassword("user@example.com", "s3cret");

Retrieve credentials

When retrieving, the user is prompted for biometric verification:

const credentials = await startiapp.Biometrics.getUsernameAndPassword(
  "Authenticate", // title shown in the biometric prompt
  "Log in to your account", // reason text
);

if (credentials) {
  console.log(credentials.username, credentials.password);
  // Use credentials to log in
} else {
  console.log("Biometric authentication failed or no saved credentials");
}

Check if credentials exist

const hasCreds = await startiapp.Biometrics.hasUsernameAndPassword();

Remove saved credentials

await startiapp.Biometrics.removeUsernameAndPassword();

Option B: Form-based flow

Hook your existing login form. The SDK captures what the user types, offers to save it behind biometrics, and on later visits logs the user in with Face ID or a fingerprint. Your page makes two calls and needs no separate code for the biometric login:

WhenCallWhat happens
Every time the login page loadsstartSaveUsernameAndPassword()Nothing saved yet: listens on the submit button and captures the fields when the user signs in. A login is saved: prompts for biometrics, fills in the form and clicks your submit button.
After every successful loginendSaveUsernameAndPassword()First time: asks "Use Face ID next time?", and if the user agrees, prompts for Face ID once and saves the captured login when the scan succeeds. Already saved: saves without asking, so a changed password is picked up.

1. When the login page loads

await startiapp.Biometrics.startSaveUsernameAndPassword({
  usernameInputFieldSelector: "#email",
  passwordInputFieldSelector: "#password",
  submitButtonSelector: "#login-button",
  title: "Sign in with {biometricsType}", // shown in the biometric prompt
  reason: "To fill in your login",
  language: "en", // or "da", for the "use biometrics next time?" dialog
});

Call it once per page load, not on every render. {biometricsType} in title and reason is replaced with "Face ID" or "Fingerprint".

2. After a successful login

await startiapp.Biometrics.endSaveUsernameAndPassword();

Call it after every successful login, the biometric one included. It only saves credentials the user typed into the form, so after a biometric login it does nothing. When nothing was captured it does not ask the user either. When the user agrees, it prompts for Face ID right away with your title and reason. That is also when iOS asks for permission to use Face ID, and the login is saved only if the scan succeeds. It resolves without an error when the user declines, cancels the scan or nothing was captured. Use hasUsernameAndPassword() if you need to know whether a login is saved.

If the page navigates after login, call it on the page you land on. The captured credentials are kept in session storage until then.

To ask "use biometrics next time?" in your own design instead of the SDK's bottom sheet, pass presentConsent. See Asking in your own design.

3. The next visit

Nothing new to call. The login page loads and calls startSaveUsernameAndPassword() again. Because a login is now saved, the user sees the biometric prompt straight away. The form is then filled in and submitted for them.

Using a button instead of a prompt on load

To let the user choose when to use biometrics, add a button and pass its selector as executingButtonSelector. startSaveUsernameAndPassword() then does not prompt on load:

await startiapp.Biometrics.startSaveUsernameAndPassword({
  usernameInputFieldSelector: "#email",
  passwordInputFieldSelector: "#password",
  submitButtonSelector: "#login-button",
  executingButtonSelector: "#face-id-button",
  title: "Sign in with {biometricsType}",
  reason: "To fill in your login",
});
  • No login saved: the SDK hides the button.
  • A login is saved: tapping the button prompts for biometrics, fills in the form and submits it.

Render the button visible and let the SDK hide it.

Logging out

Saved credentials stay on the device until removed. If the next person using the device should not be able to log in with biometrics, remove them at logout:

await startiapp.Biometrics.removeUsernameAndPassword();

Checking biometric availability

const type = await startiapp.Biometrics.getAuthenticationType();
// Returns: "face" | "fingerprint" | "none"

See also

On this page