BiometricsService User Experience
Use the BiometricsService API
BiometricsService Example
Compatibility and Requirements
Considerations and Limitations
Previous Versions
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.
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.
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}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
3 .isBiometricsReady(options)
4 .then((results) => {
5 console.log(results);
6 })
7 .catch((error) => {
8 // Handle cancellation or other errors here
9 console.error("Error code: " + error.code);
10 +console.error("Error message: " + error.message);
11 });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
3 .checkUserIsDeviceOwner(options)
4 .then((results) => {
5 // Do something with the event(s) data
6 this.events = results;
7 console.log(results);
8 })
9 .catch((error) => {
10 // Handle cancellation or other errors here
11 this.events = [];
12 console.error("Error code: " + error.code);
13 +console.error("Error message: " + error.message);
14 });See Also