Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public AuthCallback(final Promise promise) {
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
this.promise.reject(biometricPromptErrName(errorCode), TYPE_BIOMETRICS);
this.promise.reject(biometricPromptErrName(errorCode), biometricPromptErrName(errorCode));
}

@Override
Expand Down Expand Up @@ -115,7 +115,7 @@ public BiometricPrompt getBiometricPrompt(final Promise promise) {
return biometricPrompt;
}

private void biometricAuthenticate(final String description, final Promise promise) {
private void biometricAuthenticate(final String description, final String cancelButton, final Promise promise) {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
Expand All @@ -125,7 +125,7 @@ public void run() {
PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setDeviceCredentialAllowed(false)
.setConfirmationRequired(false)
.setNegativeButtonText("Cancel")
.setNegativeButtonText(cancelButton)
.setTitle(description)
.build();

Expand All @@ -146,7 +146,7 @@ private String biometricPromptErrName(int errCode) {
case BiometricPrompt.ERROR_LOCKOUT:
return "DeviceLocked";
case BiometricPrompt.ERROR_LOCKOUT_PERMANENT:
return "DeviceLocked";
return "DeviceLockedPermanent";
case BiometricPrompt.ERROR_NEGATIVE_BUTTON:
return "UserCancel";
case BiometricPrompt.ERROR_NO_BIOMETRICS:
Expand Down Expand Up @@ -188,19 +188,18 @@ private String getSensorError() {
}

@ReactMethod
public void authenticate(String description, final Promise promise) {
public void authenticate(String description, String cancelButton, final Promise promise) {
if (requiresLegacyAuthentication()) {
legacyAuthenticate(promise);
}
else {
final String errorName = getSensorError();
if (errorName != null) {
promise.reject(errorName, TYPE_BIOMETRICS);
ReactNativeFingerprintScannerModule.this.release();
promise.reject(errorName, errorName);
return;
}

biometricAuthenticate(description, promise);
biometricAuthenticate(description, cancelButton, promise);
}
}

Expand Down Expand Up @@ -234,13 +233,12 @@ public void isSensorAvailable(final Promise promise) {
// current API
String errorName = getSensorError();
if (errorName != null) {
promise.reject(errorName, TYPE_BIOMETRICS);
promise.reject(errorName, errorName);
} else {
promise.resolve(TYPE_BIOMETRICS);
}
}


// for Samsung/MeiZu compat, Android v16-23
private FingerprintIdentify getFingerprintIdentify() {
if (mFingerprintIdentify != null) {
Expand Down Expand Up @@ -287,13 +285,17 @@ private void legacyAuthenticate(final Promise promise) {
@Override
public void onSucceed() {
promise.resolve(true);
ReactNativeFingerprintScannerModule.this.release();
}

@Override
public void onNotMatch(int availableTimes) {
mReactContext.getJSModule(RCTDeviceEventEmitter.class)
.emit("FINGERPRINT_SCANNER_AUTHENTICATION", "AuthenticationNotMatch");
if( availableTimes <= 0 ){
mReactContext.getJSModule(RCTDeviceEventEmitter.class)
.emit("FINGERPRINT_SCANNER_AUTHENTICATION", "AuthenticationLockout");
}else{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if( availableTimes <= 0 ){
mReactContext.getJSModule(RCTDeviceEventEmitter.class)
.emit("FINGERPRINT_SCANNER_AUTHENTICATION", "AuthenticationLockout");
}else{
if (availableTimes <= 0) {
mReactContext.getJSModule(RCTDeviceEventEmitter.class)
.emit("FINGERPRINT_SCANNER_AUTHENTICATION", "AuthenticationLockout");
} else {

I think general whitespace style (the majority at least) is like this in the file

mReactContext.getJSModule(RCTDeviceEventEmitter.class)
.emit("FINGERPRINT_SCANNER_AUTHENTICATION", "AuthenticationNotMatch");
}
}

@Override
Expand All @@ -303,7 +305,6 @@ public void onFailed(boolean isDeviceLocked) {
} else {
promise.reject("AuthenticationFailed", TYPE_FINGERPRINT_LEGACY);
}
ReactNativeFingerprintScannerModule.this.release();
}

@Override
Expand Down
13 changes: 9 additions & 4 deletions src/authenticate.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import createError from './createError';

const { ReactNativeFingerprintScanner } = NativeModules;

const authCurrent = (description, resolve, reject) => {
ReactNativeFingerprintScanner.authenticate(description)
const authCurrent = (description, cancelButton, resolve, reject) => {
ReactNativeFingerprintScanner.authenticate(description, cancelButton)
.then(() => {
resolve(true);
})
Expand Down Expand Up @@ -38,11 +38,16 @@ const authLegacy = (onAttempt, resolve, reject) => {

const nullOnAttempt = () => null;

export default ({ description, onAttempt }) => {
export default ({ description, cancelButton, onAttempt }) => {
return new Promise((resolve, reject) => {
if (!description) {
description = "Log In";
}

if (!cancelButton) {
cancelButton = "Cancel";
}

if (!onAttempt) {
onAttempt = nullOnAttempt;
}
Expand All @@ -51,6 +56,6 @@ export default ({ description, onAttempt }) => {
return authLegacy(onAttempt, resolve, reject);
}

return authCurrent(description, resolve, reject);
return authCurrent(description, cancelButton, resolve, reject);
});
}