Biometrics
Authenticate users with device biometrics (Face ID, Touch ID, fingerprint) and securely store credentials or arbitrary data in the device keychain.
Access: startiapp.Biometrics
For step-by-step guides to implementing biometric login — see Biometric Login and Biometric Login with OAuth.
Methods
scan(title?, reason?): Promise<boolean>
Triggers a biometric scan (fingerprint or face recognition) and returns whether it succeeded.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| title | string | No | "Prove you have fingers!" | The title shown in the biometric prompt |
| reason | string | No | "Can't let you in if you don't." | The reason/subtitle shown in the prompt |
Returns: Promise<boolean> —true if the scan was successful.
Example:
const success = await startiapp.Biometrics.scan(
"Verify Identity",
"Please authenticate to continue"
);
if (success) {
console.log("Biometric scan passed");
}getAuthenticationType(): Promise<BiometricsAuthenticationType>
Returns the type of biometric authentication available on the device.
Returns: Promise<BiometricsAuthenticationType> —"face", "fingerprint", or "none".
Example:
const type = await startiapp.Biometrics.getAuthenticationType();
if (type === "face") {
console.log("Face ID available");
} else if (type === "fingerprint") {
console.log("Fingerprint available");
} else {
console.log("No biometrics available");
}checkAccess(): Promise<PermissionStatus>
Checks the current permission status for biometrics on the device.
Returns: Promise<PermissionStatus> —Object with a granted boolean.
Example:
const status = await startiapp.Biometrics.checkAccess();
if (status.granted) {
console.log("Biometrics access granted");
}setSecuredContent(content: unknown): Promise<void>
Saves arbitrary content to the device's secure keychain storage. The content is JSON-serialized before storing.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| content | unknown | Yes | The data to store (will be JSON-serialized) |
Returns: Promise<void>
Example:
await startiapp.Biometrics.setSecuredContent({
apiToken: "abc123",
refreshToken: "xyz789",
});getSecuredContent<T>(title?, reason?): Promise<T | null>
Retrieves previously stored secured content. Triggers a biometric scan to authorize access.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| title | string | No | "Prove you have fingers!" | The biometric prompt title |
| reason | string | No | "Can't let you in if you don't." | The biometric prompt reason |
Returns: Promise<T | null> —The deserialized content, or null if nothing is stored or parsing fails.
Example:
interface Tokens {
apiToken: string;
refreshToken: string;
}
const tokens = await startiapp.Biometrics.getSecuredContent<Tokens>(
"Access Tokens",
"Authenticate to retrieve your saved tokens"
);
if (tokens) {
console.log("API Token:", tokens.apiToken);
}hasSecuredContent(): Promise<boolean>
Checks whether secured content exists in the keychain without triggering a biometric scan.
Returns: Promise<boolean> —true if secured content exists.
Example:
const hasContent = await startiapp.Biometrics.hasSecuredContent();
if (hasContent) {
console.log("Secured content is stored");
}removeSecuredContent(): Promise<void>
Removes the secured content from the keychain.
Returns: Promise<void>
Example:
await startiapp.Biometrics.removeSecuredContent();setUsernameAndPassword(username, password): Promise<void>
Saves a username and password pair to the device's secure keychain.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| username | string | Yes | The username to store |
| password | string | Yes | The password to store |
Returns: Promise<void>
Example:
await startiapp.Biometrics.setUsernameAndPassword("john@example.com", "s3cret");getUsernameAndPassword(title?, reason?): Promise<{ username: string; password: string } | null>
Retrieves the saved username and password. Triggers a biometric scan to authorize access.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| title | string | No | "Prove you have fingers!" | The biometric prompt title |
| reason | string | No | "Can't let you in if you don't." | The biometric prompt reason |
Returns: Promise<{ username: string; password: string } | null> —The credentials, or null if none are stored.
Example:
const credentials = await startiapp.Biometrics.getUsernameAndPassword(
"Login",
"Authenticate to auto-fill your credentials"
);
if (credentials) {
console.log("Username:", credentials.username);
// Auto-fill the login form
document.querySelector<HTMLInputElement>("#username")!.value = credentials.username;
document.querySelector<HTMLInputElement>("#password")!.value = credentials.password;
}hasUsernameAndPassword(): Promise<boolean>
Checks whether a username and password pair is stored without triggering a biometric scan.
Returns: Promise<boolean> —true if credentials are stored.
Example:
const hasCreds = await startiapp.Biometrics.hasUsernameAndPassword();
if (hasCreds) {
console.log("Saved credentials available — show biometric login button");
}removeUsernameAndPassword(): Promise<void>
Removes the saved username and password from the keychain.
Returns: Promise<void>
Example:
await startiapp.Biometrics.removeUsernameAndPassword();startSaveUsernameAndPassword(request): Promise<void>
Hooks a login form for biometric login. Call it every time the login page loads. It does two things:
- Captures: it listens on the submit button and holds the username and password when the user submits the form. After a successful login, call
endSaveUsernameAndPassword()to save them. - Logs in: if a login is already saved, it prompts for biometrics with
titleandreason, fills in the form and clicks the submit button. IfexecutingButtonSelectoris set, it does this when that button is tapped instead of straight away, and hides the button when no login is saved.
See Biometric login for the whole flow.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| request | SaveUsernameAndPasswordConfiguration | Yes | Configuration for form selectors and localization |
Returns: Promise<void>
Example:
await startiapp.Biometrics.startSaveUsernameAndPassword({
usernameInputFieldSelector: "#username",
passwordInputFieldSelector: "#password",
submitButtonSelector: "#login-button",
title: "Save Login",
reason: "Save your credentials for quick login next time",
language: "en",
});endSaveUsernameAndPassword(config?): Promise<void>
Completes the credential capture flow. Call this after every successful login, including one made with biometrics. If no login is saved yet, it asks the user whether to use biometrics next time. If they agree, it prompts for biometrics once with the title and reason you passed to startSaveUsernameAndPassword(), and saves the captured credentials only if that scan succeeds. If a login is already saved, it overwrites it without asking or prompting.
The scan confirms the choice while the user is making it. On iOS the first scan is also when the system asks for permission to use Face ID, so that question comes right after the user said yes rather than at their next login.
It only saves credentials the user typed into the form after startSaveUsernameAndPassword(). When nothing was captured it does not ask the user. It resolves without an error when the user declines, cancels the scan, when no biometrics are available or when nothing was captured. Check with hasUsernameAndPassword() if you need to know the outcome.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| config | EndSaveUsernameAndPasswordConfiguration | No | Optional key to identify the configuration, and an optional presentConsent to ask the user in your own design |
Returns: Promise<void>
Example:
// After successful login
await startiapp.Biometrics.endSaveUsernameAndPassword();Asking in your own design
By default the SDK asks "use biometrics next time?" in its own bottom sheet, and you can only change its texts. To show your own dialog instead, pass presentConsent. The SDK calls it in place of its bottom sheet. When it returns true, the SDK prompts for biometrics as described above and saves the login if the scan succeeds. false, any other value or a thrown error means the user declined, and nothing is saved.
presentConsent is called only when there is something to ask about: a login was captured, biometrics are available and no login is saved yet. It is not called until the intro flow has closed. It receives the biometrics type ("face" or "fingerprint"), so your dialog can say "Face ID" or "fingerprint".
This example shows a bottom sheet with a toggle and a confirm button. The close button counts as declining:
await startiapp.Biometrics.endSaveUsernameAndPassword({
presentConsent: (biometricsType) =>
new Promise<boolean>((resolve) => {
const sheet = document.querySelector<HTMLElement>("#biometrics-sheet")!;
const toggle = sheet.querySelector<HTMLInputElement>("#biometrics-toggle")!;
const label = biometricsType === "face" ? "Face ID" : "fingeraftryk";
sheet.querySelector("#biometrics-label")!.textContent = `Brug ${label} til at logge ind`;
toggle.checked = false;
const close = (answer: boolean) => {
sheet.hidden = true;
resolve(answer);
};
sheet.querySelector("#biometrics-confirm")!.addEventListener("click", () => close(toggle.checked), { once: true });
sheet.querySelector("#biometrics-close")!.addEventListener("click", () => close(false), { once: true });
sheet.hidden = false;
}),
});Types
BiometricsAuthenticationType
type BiometricsAuthenticationType = "none" | "face" | "fingerprint";PermissionStatus
interface PermissionStatus {
granted: boolean;
}SaveUsernameAndPasswordConfiguration
Full configuration for the automated credential capture flow. Combines form selectors with internationalization settings.
type SaveUsernameAndPasswordConfiguration = {
key?: string;
} & SaveUsernameAndPasswordConfigurationSelectors &
SaveUsernameAndPasswordI18n;SaveUsernameAndPasswordConfigurationSelectors
type SaveUsernameAndPasswordConfigurationSelectors = {
usernameInputFieldSelector: string;
passwordInputFieldSelector: string;
submitButtonSelector: string;
executingButtonSelector?: string;
};| Field | Description |
|---|---|
usernameInputFieldSelector | CSS selector for the username input |
passwordInputFieldSelector | CSS selector for the password input |
submitButtonSelector | CSS selector for the button that submits the login |
executingButtonSelector | Optional. CSS selector for a "Log in with Face ID" button. When set, the biometric login runs when the button is tapped instead of on load. The SDK hides the button when no login is saved. |
SaveUsernameAndPasswordI18n
Internationalization options for the biometric consent dialog. Provide one of three options:
- A built-in
language("da"or"en"). When it is left out, the texts are Danish if the page's<html lang>(or, without one, the device language) is Danish, and English otherwise. - A
confirmMessageTemplatewith optional biometrics type translations. The template becomes the dialog's question, and the buttons use the built-in texts in the language chosen as above. - Full custom
translations
title and reason are not shown in this dialog. They are used in the system's biometric prompt: once when the user agrees and the login is saved, and every time the saved login is used. Word them so they fit both, for example "Sign in with {biometricsType}".
type SaveUsernameAndPasswordI18n = {
title: string;
reason: string;
} & (
| { language?: "da" | "en" }
| {
confirmMessageTemplate: string;
biometricsTypeTranslations?: {
face: string;
fingerprint: string;
};
}
| {
translations: {
nextTime: {
title: string;
subtitle: string;
acceptedButtonText: string;
declinedButtonText: string;
};
biometricsType: {
face: string;
fingerprint: string;
};
};
}
);EndSaveUsernameAndPasswordConfiguration
type EndSaveUsernameAndPasswordConfiguration = {
key?: string;
presentConsent?: (
biometricsType: "face" | "fingerprint"
) => boolean | Promise<boolean>;
};| Field | Description |
|---|---|
key | Optional. The same key you passed to startSaveUsernameAndPassword(), if any |
presentConsent | Optional. Asks the user in your own design instead of the SDK's bottom sheet. Return true to save the login. See Asking in your own design |
BiometricsResultResponse
type BiometricsResultResponse<T> = {
key: string;
result: T;
};