my.startLocalBioAuth
The my.startLocalBioAuth JSAPI is called by mini programs to initiate a biometric authentication process on the user's device.
Request parameter
Field | Date type | Required | Description |
fallbackType | Number | No | The alternative authentication method when biometric authentication fails. Valid values are:
If you do not specify this parameter, its value is set to |
promptText | String | Yes | The text that is displayed on the biometric prompt. To avoid truncation and enhance user experience, it is recommended to use short and clear text to state the authentication purpose. |
success | Function | No | The callback that is executed when the authentication is successful. If you need to set callbacks for this JSAPI, either specify this parameter and the fail parameter or specify the complete parameter. |
fail | Function | No | The callback that is executed when the authentication fails. If you need to set callbacks for this JSAPI, either specify this parameter and the success parameter or specify the complete parameter. |
complete | Function | No | The callback that is executed when the authentication process ends, regardless of success or failure. If you need to set callbacks for this JSAPI, either specify this parameter or specify the success and the fail parameters. |
Response parameter
Field | Data type | Required | Description |
success | Boolean | No | Whether the biometric authentication is successful. This parameter is returned if the success or complete callback function is executed. Valid values are:
|
error | Number | No | The error code. For more information, refer to Error codes. This parameter is returned if the fail callback function is executed or if the success response parameter is set to |
errorMessage | String | No | The error message that corresponds to the error code. For more information, refer to Error codes. This parameter is returned if the fail callback function is executed or if the success response parameter is set to |
Error codes
Error code | Error message | Further action |
11 | The authentication process was canceled by the user. | N/A |
12 | Either the device lacks biometric support or the super app cannot access the biometric feature. | Use other methods to authenticate the user if necessary. |
13 | Biometric credentials are not enabled on the user's device. | Use other methods to authenticate the user if necessary. |
99 | An undefined error has occurred. Please contact technical support for assistance. | Please contact technical support for assistance. |
Sample code
The following sample code shows how to call the my.startLocalBioAuth JSAPI:
my.startLocalBioAuth({
fallbackType: 1,
promptText: "Authenticate to unlock",
success: (res) => {
console.log(JSON.stringify(res))
},
fail: (res) => {
console.log(JSON.stringify(res))
if (res.error == 11) {
// Logic to be executed when the authentication process is canceled by the user.
}
},
});