Actualizado el 21. marzo 2026 por Jan Bunk
¿Quieres mejorar la seguridad de tu aplicación manteniendo una gran usabilidad? La autenticación local puede ser el camino a seguir. Esta documentación te mostrará cómo puedes pedir a los usuarios de tu aplicación que introduzcan el PIN, la huella dactilar o el Face ID de su dispositivo antes de acceder a partes de tu aplicación.
Activa el permiso de biometría en tu configuración de permisos. De lo contrario, esta función podría funcionar solo parcialmente (sin Face ID) o romperse de forma inesperada.
executeWhenAppReady() de nuestro script de ayuda de la aplicación. Garantiza que tu sitio web no intente interactuar con la aplicación antes de que esté lista o cuando tu sitio web se cargue utilizando un navegador normal (ReferenceError, function is not defined). requestLocalAuthenticationUtiliza esta función para pedir al usuario su autenticación.
La función devuelve un objeto con un resultado booleano si tiene éxito. Si se cancela el aviso de autenticación o el dispositivo no puede continuar, en su lugar lanza un código de error en forma de string.
<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>
Las versiones antiguas de la app puede que todavía estén manejando strings de error como NotAvailable, PasscodeNotSet, LockedOut y PermanentlyLockedOut.