Use the BiometricsService API

To develop a Lightning web component with biometrics-checking features, use the BiometricsService API as your method for accessing a device’s native biometrics functionality.
  1. Import BiometricsService into your component definition to make the BiometricsService API functions available to your code.
  2. Test to make sure BiometricsService is available before you call for a biometrics check.
  3. Use the feature functions to prompt app users for biometrics checks.

Add BiometricsService to a Lightning Web Component

In your component’s JavaScript file, import BiometricsService using the standard JavaScript import statement. Specifically, import the getBiometricsService() factory function from the lightning/mobileCapabilities module, like so:

1import { getBiometricsService } from 'lightning/mobileCapabilities';

After it’s imported into your component, use the factory function to get an instance of BiometricsService. With your BiometricsService instance, use the utility functions and constants to verify availability. Then use the feature functions to perform the associated functionality.

Test BiometricsService Availability

BiometricsService depends on physical device hardware and platform features. A component that uses BiometricsService renders without errors on a desktop computer or in a mobile browser, but biometrics-checking functions fail. To avoid these errors, test if BiometricsService functionality is available before you use it.

1handleCheckBiometricsClick(event) {
2    const myBiometricsService = getBiometricsService();
3    if(myBiometricsService.isAvailable()) {
4        // Perform biometrics-checking operations
5    }
6    else {
7        // BiometricsService not available, or consuming app hasn’t implemented it         
8        // Not running on hardware with biometrics functionality, etc.
9        // Handle with message, error, beep, and so on
10    }
11}

Check Biometrics Availability and Configuration

It’s simple to confirm a device’s biometrics functionality in your Lightning web component using BiometricsService. First, use isBiometricsReady() to confirm that a device has biometrics functionality and that it’s set up for use. Then, process the result in whatever manner you wish.

For example:

1// Check for device biometrics functionality, console log the results
2myBiometricsService.isBiometricsReady(options)
3.then((results) => {
4    console.log(results);
5})
6.catch((error) => {
7    // Handle cancellation or other errors here
8    console.error('Error code: ' + error.code); + 
9    console.error('Error message: ' + error.message);
10});

Prompt a Biometric Check

Prompt a device biometrics check with the checkUserIsDeviceOwner() function. First, call the checkUserIsDeviceOwner() function, optionally including a BiometricsServiceOptions parameter. Then, handle the outcome in whatever manner you wish.

For example:

1// Get events from a specified date range from the specified calendar(s), and then   process them
2myBiometricsService.checkUserIsDeviceOwner(options)
3.then((results) => {
4    // Do something with the event(s) data
5    this.events = results;
6    console.log(results);
7})
8.catch((error) => {
9    // Handle cancellation or other errors here
10    this.events = [];
11    console.error('Error code: ' + error.code); + 
12    console.error('Error message: ' + error.message);
13});