Parameters
| Property | Type | Required | Description |
|---|---|---|---|
| success | Function | No | Callback on success |
| fail | Function | No | Callback on failure |
| complete | Function | No | Callback that always executes |
Success Callback Parameters
| Property | Type | Description |
|---|---|---|
| success | Boolean | Whether biometric authentication is available on the user’s device. Returned by the success or complete callback. |
| error | Number | The error code. Returned by the fail callback, or by the complete callback when success is false. See Error Codes below. |
| errorMessage | String | The error message corresponding to the error code. |
Error Codes
| Code | Description |
|---|---|
| 12 | Either the device lacks biometric support or the super app cannot access the biometric feature. |
| 13 | Biometric credentials are not enabled on the user’s device. |
| 99 | An undefined error has occurred. Please contact technical support for assistance. |
Code Example
Basic Usage
my.checkLocalBioAuthSupported({
success(res) {
console.log('Biometric available:', res.success);
},
fail(res) {
console.error('Error code:', res.error);
}
});
Conditional UI
Page({
data: {
biometricAvailable: false
},
onLoad() {
my.checkLocalBioAuthSupported({
success: (res) => {
this.setData({
biometricAvailable: res.success
});
}
});
}
});
Smart Authentication
Page({
authenticate() {
my.checkLocalBioAuthSupported({
success: (res) => {
if (res.success) {
this.useBiometric();
} else {
this.usePasswordAuth();
}
},
fail: () => {
this.usePasswordAuth();
}
});
},
useBiometric() {
my.startLocalBioAuth({
promptText: 'Verify your identity',
success: (res) => {
if (res.success) {
this.onAuthSuccess();
}
},
fail: () => {
// Fall back to password
this.usePasswordAuth();
}
});
},
usePasswordAuth() {
// Show password input
},
onAuthSuccess() {
// Proceed with authenticated action
}
});
Handling Errors
Page({
data: {
authMethods: []
},
onLoad() {
my.checkLocalBioAuthSupported({
success: (res) => {
this.setData({
authMethods: res.success ? ['Biometric', 'Password'] : ['Password']
});
},
fail: (res) => {
console.log('Error code:', res.error, res.errorMessage);
this.setData({ authMethods: ['Password'] });
}
});
}
});
Always check biometric availability before showing biometric options in your UI to avoid confusing users on devices without biometric capabilities.
Related APIs
my.startLocalBioAuth
Start biometric verification