Bijgewerkt op 21. maart 2026 door Jan Bunk
Wil je de beveiliging van je app verbeteren en toch een goede bruikbaarheid behouden? Dan is lokale authenticatie misschien een goede optie. We leggen je uit hoe je de gebruikers van je app kunt vragen om hun pincode/vingerafdruk/gezichtsidentificatie in te voeren voordat ze toegang krijgen tot delen van je app.
Schakel de toestemming voor biometrie in je toestemmingsinstellingen in. Anders kan deze functie slechts gedeeltelijk werken (geen Face-ID) of op onverwachte manieren niet meer werken.
executeWhenAppReady() functie van ons app-helper script. Het zorgt ervoor dat je website niet probeert te communiceren met de app voordat deze klaar is of wanneer je website wordt geladen met een gewone browser (ReferenceError, functie is niet gedefinieerd). requestLocalAuthenticationGebruik deze functie om de gebruiker om authenticatie te vragen.
De functie retourneert bij succes een object met een booleaanse uitkomst. Als de authenticatieprompt wordt geannuleerd of het apparaat niet verder kan, gooit hij in plaats daarvan een string-foutcode.
<script>
try {
// This message will be displayed to the user along with the prompt.
let reason = "Please authenticate to access this part of the app";
// Returns a boolean. True if the authentication was successful, false if the authentication challenge failed.
// If the prompt is canceled or the device cannot continue, an error string is thrown instead.
let authenticationResult = (await requestLocalAuthentication(reason))["result"];
}
catch (e) {
switch(e) {
case "userCanceled":
// The user canceled the prompt and didn't authenticate.
break;
case "authInProgress":
// Another authentication request is already running.
break;
case "noCredentialsSet":
// No biometrics, PIN, password, or pattern is configured.
break;
case "systemCanceled":
// The system interrupted the authentication attempt, for example when the app gets closed.
break;
// All the errors below should be very rare in practice:
case "timeout":
// The authentication prompt timed out.
break;
case "uiUnavailable":
// The system cannot show the authentication prompt right now.
break;
case "deviceError":
// A device-level error prevented authentication.
break;
case "unknownError":
// An unknown error occurred.
break;
default:
// Any other error
break;
}
}
</script>
Oudere app-versies verwerken mogelijk nog steeds fout-strings zoals NotAvailable, PasscodeNotSet, LockedOut en PermanentlyLockedOut.