getBiometricsService().isAvailable()
const biometricsService = getBiometricsService();
biometricsService.isAvailable().then(isAvailable => {
if (isAvailable) {
// Proceed with biometric operations
}
});
getBiometricsService().isBiometricsReady(options)
biometricsService.isBiometricsReady(options).then(isReady => {
if (isReady) {
// Device is ready for biometric authentication
}
});
getBiometricsService().checkUserIsDeviceOwner(options)
biometricsService.checkUserIsDeviceOwner(options).then(isOwner => {
if (isOwner) {
// User authenticated successfully
}
});
<template>
<lightning-card title="Biometrics Service Demo" icon-name="custom:privately_shared">
<div class="slds-var-m-around_medium">
Use device biometrics capabilities to verify current user is indeed device owner:
<lightning-button
variant="brand"
label="Verify"
title="Verify device ownership using biometrics"
onclick={handleVerifyClick}
class="slds-var-m-left_x-small">
</lightning-button>
</div>
<div class="slds-var-m-around_medium">
<lightning-formatted-text value={status}></lightning-formatted-text>
</div>
</lightning-card>
</template>
import {LightningElement} from 'lwc';
import {getBiometricsService} from 'lightning/mobileCapabilities';
export default class BioService extends LightningElement {
status;
biometricsService;
connectedCallback() {
this.biometricsService = getBiometricsService();
}
handleVerifyClick() {
if (this.biometricsService.isAvailable()) {
const options = {
permissionRequestBody: "Required to confirm device ownership.",
additionalSupportedPolicies: ['PIN_CODE']
};
this.biometricsService.checkUserIsDeviceOwner(options)
.then((result) => {
// Do something with the result
if (result === true) {
this.status = "✔ Current user is device owner."
} else {
this.status = "𐄂 Current user is NOT device owner."
}
})
.catch((error) => {
// Handle errors
this.status = 'Error code: ' + error.code + '\nError message: ' + error.message;
});
} else {
// service not available
this.status = 'Problem initiating Biometrics service. Are you using a mobile device?';
}
}
}
The service is available on iOS and Android apps but is not supported on desktop.
import {api, LightningElement, wire} from 'lwc';
import {getBiometricsService} from "lightning/mobileCapabilities";
import {updateRecord} from 'lightning/uiRecordApi';
import ID_FIELD from '@salesforce/schema/Order.Id';
import STATUS from '@salesforce/schema/Order.Status';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
export default class FirstBiometricService extends LightningElement {
biometricsService;
@api
recordId;
connectedCallback() {
this.biometricsService = getBiometricsService();
this.handleVerifyClick();
}
handleVerifyClick() {
if (this.biometricsService.isAvailable()) {
const options = {
permissionRequestBody: "Required to confirm device ownership.",
additionalSupportedPolicies: ['PIN_CODE']
};
this.biometricsService.checkUserIsDeviceOwner(options)
.then((result) => {
if (result === true) {
this.status = "✔ Current user is device owner."
const fields = {};
fields[ID_FIELD.fieldApiName] = this.recordId;
fields[STATUS.fieldApiName] = 'Activated';
const recordInput = { fields };
updateRecord(recordInput)
.then(() => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'Order submitted',
variant: 'success'
})
);
})
.catch(error => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error updating record',
message: this.recordId,
variant: 'error'
})
);
})
} else {
this.status = "𐄂 Current user is NOT device owner."
}
})
.catch((error) => {
this.status = 'Error code: ' + error.code + '\nError message: ' + error.message;
});
} else {
this.status = 'Problem initiating Biometrics service. Are you using a mobile device?';
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<description>First Biometric Service</description>
<isExposed>true</isExposed>
<masterLabel>First Biometric Service</masterLabel>
<targets>
<target>lightning__AppPage</target>
<target>lightning__Tab</target>
<target>lightning__RecordPage</target>
<target>lightning__RecordAction</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordPage">
<supportedFormFactors>
<supportedFormFactor type="Small"/>
</supportedFormFactors>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>