Skip to main content
Use this API to authenticate the user using biometric methods such as fingerprint or face recognition.

Parameters

PropertyTypeRequiredDescription
typeStringYesBiometric type: fingerPrint or facial
titleStringNoCustom title for the authentication dialog
successFunctionNoCallback on success
failFunctionNoCallback on failure
completeFunctionNoCallback that always executes

Success Callback Parameters

PropertyTypeDescription
successBooleanWhether authentication was successful

Code Example

Basic Fingerprint Authentication

my.startLocalBioAuth({
  type: 'fingerPrint',
  success(res) {
    if (res.success) {
      console.log('Fingerprint verified');
    }
  },
  fail(err) {
    console.error('Authentication failed:', err);
  }
});

Face Recognition

my.startLocalBioAuth({
  type: 'facial',
  title: 'Verify your identity',
  success(res) {
    if (res.success) {
      console.log('Face verified');
    }
  }
});

Secure Payment Flow

Page({
  async confirmPayment() {
    // First verify user identity
    my.startLocalBioAuth({
      type: 'fingerPrint',
      title: 'Confirm payment',
      success: (res) => {
        if (res.success) {
          this.processPayment();
        } else {
          my.showToast({
            content: 'Verification failed',
            type: 'fail'
          });
        }
      },
      fail: (err) => {
        // Biometric not available, fall back to PIN
        this.showPinEntry();
      }
    });
  },

  processPayment() {
    // Proceed with payment
  },

  showPinEntry() {
    // Show PIN input as fallback
  }
});

Check Biometric Availability First

Page({
  async authenticateUser() {
    // Check if biometric is available
    my.checkLocalBioAuthSupported({
      success: (res) => {
        if (res.available) {
          my.startLocalBioAuth({
            type: res.type, // Use available type
            success: (verifyRes) => {
              if (verifyRes.success) {
                this.onAuthSuccess();
              }
            }
          });
        } else {
          // Biometric not available
          this.useFallbackAuth();
        }
      }
    });
  },

  onAuthSuccess() {
    my.showToast({ content: 'Authenticated' });
  },

  useFallbackAuth() {
    // Use password or PIN
  }
});

Error Codes

CodeDescription
10001Biometric not supported on device
10002Biometric not enrolled
10003User cancelled authentication
10004Authentication failed
Biometric authentication may not be available on all devices. Always provide a fallback authentication method.

my.checkLocalBioAuthSupported

Check availability