Skip to content

Latest commit

 

History

History
78 lines (46 loc) · 4.53 KB

local-authentication.md

File metadata and controls

78 lines (46 loc) · 4.53 KB
title sourceCodeUrl
LocalAuthentication

import InstallSection from '/components/plugins/InstallSection'; import PlatformsSection from '/components/plugins/PlatformsSection'; import TableOfContentSection from '~/components/plugins/TableOfContentSection';

expo-local-authentication allows you to use FaceID and TouchID (iOS) or the Biometric Prompt (Android) to authenticate the user with a face or fingerprint scan.

<PlatformsSection android emulator ios simulator web={{ pending: '#4045' }} />

Installation

API

import * as LocalAuthentication from 'expo-local-authentication';

<TableOfContentSection title='Methods' contents={['LocalAuthentication.hasHardwareAsync()', 'LocalAuthentication.supportedAuthenticationTypesAsync()', 'LocalAuthentication.isEnrolledAsync()', 'LocalAuthentication.authenticateAsync(options)', 'LocalAuthentication.cancelAuthenticate()']} />

Methods

LocalAuthentication.hasHardwareAsync()

Determine whether a face or fingerprint scanner is available on the device.

Returns

Returns a promise resolving to boolean value indicating whether a face or fingerprint scanner is available on this device.

LocalAuthentication.supportedAuthenticationTypesAsync()

Determine what kinds of authentications are available on the device.

Returns

Returns a promise resolving to an array containing any of the types below. If neither authentication type is supported, returns an empty array.

  • LocalAuthentication.AuthenticationType.BIOMETRIC indicates either Fingerprint or Facial Recognition support
  • LocalAuthentication.AuthenticationType.FINGERPRINT indicates Fingerprint support iOS only
  • LocalAuthentication.AuthenticationType.FACIAL_RECOGNITION indicates Facial Recognition support iOS only

Note: On Android, this only returns the BIOMETRIC type if fingerprint or facial recognition is available. The new BiometricPrompt doesn't allow selecting a specific method of biometric authentication.

LocalAuthentication.isEnrolledAsync()

Determine whether the device has saved fingerprints or facial data to use for authentication.

Returns

Returns a promise resolving to boolean value indicating whether the device has saved fingerprints or facial data for authentication.

LocalAuthentication.authenticateAsync(options)

Attempts to authenticate via Fingerprint/TouchID (or FaceID if available on the device).

Note: Apple requires apps which use FaceID to provide a description of why they use this API. If you try to use FaceID on an iPhone with FaceID without providing infoPlist.NSFaceIDUsageDescription in app.json, the module will authenticate using device passcode. For more information about usage descriptions on iOS, see Deploying to App Stores.

Arguments

  • options (object) -- An object of options.
    • promptMessage (string) -- A message that is shown alongside the TouchID, FaceID or Biometric prompt.
    • cancelLabel (string) -- Allows to customize the default Cancel label shown.
    • fallbackLabel (string) -- Allows to customize the default Use Passcode label shown after several failed authentication attempts. Setting this option to an empty string disables this button from showing in the prompt. (iOS only)
    • disableDeviceFallback (boolean) -- After several failed attempts the system will fallback to the device passcode. This setting allows you to disable this option and instead handle the fallback yourself. This can be preferable in certain custom authentication workflows. This behaviour maps to using the iOS LAPolicyDeviceOwnerAuthenticationWithBiometrics policy rather than the LAPolicyDeviceOwnerAuthentication policy. Defaults to false.

Returns

Returns a promise resolving to an object containing success, a boolean indicating whether or not the authentication was successful, and error containing the error code in the case where authentication fails.

LocalAuthentication.cancelAuthenticate()

(Android Only) Cancels authentication flow.