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.
- Import BiometricsService into your component definition to make the BiometricsService API functions available to your code.
- Test to make sure BiometricsService is available before you call for a biometrics check.
- Use the feature functions to prompt app users for biometrics checks.
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:
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.
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:
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:
See Also