Atualizado em 21. março 2026 por Jan Bunk
Deseja melhorar a segurança do seu aplicativo e, ao mesmo tempo, manter uma excelente usabilidade? A autenticação local pode ser o caminho a seguir. Esta documentação mostrará como você pode solicitar que os usuários do seu aplicativo digitem o PIN do dispositivo, a impressão digital ou o ID facial antes de acessar partes do aplicativo.
Habilite a permissão biométrica em suas configurações de permissão. Caso contrário, este recurso pode funcionar apenas parcialmente (sem identificação facial) ou quebrar de maneiras inesperadas.
executeWhenAppReady() do nosso script auxiliar de aplicação. Ele garante que seu site não tente interagir com o aplicativo antes que ele esteja pronto ou quando o site for carregado usando um navegador comum (ReferenceError, a função não está definida). requestLocalAuthenticationUse esta função para solicitar a autenticação do usuário.
The function returns an object with a boolean result on success. If the authentication prompt is canceled or the device cannot continue, it throws a string error code instead.
<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.
break;
case "authInProgress":
// Another authentication request is already running.
break;
case "noCredentialsSet":
// No device PIN, passcode, 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>
Older app versions may still be handling error strings such as NotAvailable, PasscodeNotSet, LockedOut, and PermanentlyLockedOut.