From 425d5ccda7c6a617e4f18e17af488ff1dd978e47 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 18 May 2020 14:56:52 -0300 Subject: [PATCH] [expo-local-authentication] Add support for `promptMessage`, `cancelLabel` and `disableDeviceFallback` on Android (#8219) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ANDROID] Add local authentication options * Unify tests * Remove empty space * Use Map * Change variables scope * Fix lint * Build * Unnecessary empty space removal * Add changelog * Update packages/expo-local-authentication/CHANGELOG.md Co-authored-by: Łukasz Kosmaty Co-authored-by: Łukasz Kosmaty --- .../src/screens/LocalAuthenticationScreen.tsx | 5 ++-- .../expo-local-authentication/CHANGELOG.md | 2 ++ .../LocalAuthenticationModule.java | 30 +++++++++++++++---- .../build/LocalAuthentication.js | 20 +++++-------- .../build/LocalAuthentication.js.map | 2 +- .../build/LocalAuthentication.types.d.ts | 2 +- .../build/LocalAuthentication.types.js.map | 2 +- .../src/LocalAuthentication.ts | 27 +++++++---------- .../src/LocalAuthentication.types.ts | 4 +-- .../LocalAuthentication-test.android.ts | 15 ---------- ....ts => LocalAuthentication-test.native.ts} | 4 +-- 11 files changed, 55 insertions(+), 58 deletions(-) delete mode 100644 packages/expo-local-authentication/src/__tests__/LocalAuthentication-test.android.ts rename packages/expo-local-authentication/src/__tests__/{LocalAuthentication-test.ios.ts => LocalAuthentication-test.native.ts} (90%) diff --git a/apps/native-component-list/src/screens/LocalAuthenticationScreen.tsx b/apps/native-component-list/src/screens/LocalAuthenticationScreen.tsx index 19fa736109ba4..865fdf724e369 100644 --- a/apps/native-component-list/src/screens/LocalAuthenticationScreen.tsx +++ b/apps/native-component-list/src/screens/LocalAuthenticationScreen.tsx @@ -33,8 +33,9 @@ export default class LocalAuthenticationScreen extends React.Component<{}, State this.setState({ waiting: true }); try { const result = await LocalAuthentication.authenticateAsync({ - promptMessage: 'This message only shows up on iOS', - fallbackLabel: '', + promptMessage: 'Authenticate', + cancelLabel: 'Cancel label', + disableDeviceFallback: true, }); if (result.success) { alert('Authenticated!'); diff --git a/packages/expo-local-authentication/CHANGELOG.md b/packages/expo-local-authentication/CHANGELOG.md index 6a294c6841ff4..98989f9974ac7 100644 --- a/packages/expo-local-authentication/CHANGELOG.md +++ b/packages/expo-local-authentication/CHANGELOG.md @@ -6,4 +6,6 @@ ### 🎉 New features +- Added support for `promptMessage`, `cancelLabel` and `disableDeviceFallback` on Android. ([#8219](https://github.com/expo/expo/pull/8219) by [@diegolmello](https://github.com/diegolmello)) + ### 🐛 Bug fixes diff --git a/packages/expo-local-authentication/android/src/main/java/expo/modules/localauthentication/LocalAuthenticationModule.java b/packages/expo-local-authentication/android/src/main/java/expo/modules/localauthentication/LocalAuthenticationModule.java index babaf55735e7c..7285e6926ce56 100644 --- a/packages/expo-local-authentication/android/src/main/java/expo/modules/localauthentication/LocalAuthenticationModule.java +++ b/packages/expo-local-authentication/android/src/main/java/expo/modules/localauthentication/LocalAuthenticationModule.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -96,7 +97,7 @@ public void isEnrolledAsync(final Promise promise) { } @ExpoMethod - public void authenticateAsync(final Promise promise) { + public void authenticateAsync(final Map options, final Promise promise) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { promise.reject("E_NOT_SUPPORTED", "Cannot display biometric prompt on android versions below 6.0"); return; @@ -130,6 +131,22 @@ public void run() { return; } + String promptMessage = ""; + String cancelLabel = ""; + boolean disableDeviceFallback = false; + + if (options.containsKey("promptMessage")) { + promptMessage = (String) options.get("promptMessage"); + } + + if (options.containsKey("cancelLabel")) { + cancelLabel = (String) options.get("cancelLabel"); + } + + if (options.containsKey("disableDeviceFallback")) { + disableDeviceFallback = (Boolean) options.get("disableDeviceFallback"); + } + mIsAuthenticating = true; mPromise = promise; mCancellationSignal = new CancellationSignal(); @@ -138,10 +155,13 @@ public void run() { Executor executor = Executors.newSingleThreadExecutor(); BiometricPrompt biometricPrompt = new BiometricPrompt(fragmentActivity, executor, mAuthenticationCallback); - BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder() - .setDeviceCredentialAllowed(true) - .setTitle("Authenticate") - .build(); + BiometricPrompt.PromptInfo.Builder promptInfoBuilder = new BiometricPrompt.PromptInfo.Builder() + .setDeviceCredentialAllowed(!disableDeviceFallback) + .setTitle(promptMessage); + if (cancelLabel != null && disableDeviceFallback) { + promptInfoBuilder.setNegativeButtonText(cancelLabel); + } + BiometricPrompt.PromptInfo promptInfo = promptInfoBuilder.build(); biometricPrompt.authenticate(promptInfo); } }); diff --git a/packages/expo-local-authentication/build/LocalAuthentication.js b/packages/expo-local-authentication/build/LocalAuthentication.js index f4d442036ea5a..53c794a793b17 100644 --- a/packages/expo-local-authentication/build/LocalAuthentication.js +++ b/packages/expo-local-authentication/build/LocalAuthentication.js @@ -1,6 +1,5 @@ import { UnavailabilityError } from '@unimodules/core'; import invariant from 'invariant'; -import { Platform } from 'react-native'; import ExpoLocalAuthentication from './ExpoLocalAuthentication'; import { AuthenticationType, } from './LocalAuthentication.types'; export { AuthenticationType }; @@ -31,20 +30,15 @@ export async function authenticateAsync(options = {}) { console.warn('String argument in LocalAuthentication.authenticateAsync has been deprecated. Please use options object with `promptMessage` key instead.'); options = { promptMessage: options }; } - if (Platform.OS === 'ios') { - if (options.hasOwnProperty('promptMessage')) { - invariant(typeof options.promptMessage === 'string' && options.promptMessage.length, 'LocalAuthentication.authenticateAsync : `options.promptMessage` must be a non-empty string.'); - } - const promptMessage = options.promptMessage || 'Authenticate'; - const result = await ExpoLocalAuthentication.authenticateAsync({ ...options, promptMessage }); - if (result.warning) { - console.warn(result.warning); - } - return result; + if (options.hasOwnProperty('promptMessage')) { + invariant(typeof options.promptMessage === 'string' && options.promptMessage.length, 'LocalAuthentication.authenticateAsync : `options.promptMessage` must be a non-empty string.'); } - else { - return await ExpoLocalAuthentication.authenticateAsync(); + const promptMessage = options.promptMessage || 'Authenticate'; + const result = await ExpoLocalAuthentication.authenticateAsync({ ...options, promptMessage }); + if (result.warning) { + console.warn(result.warning); } + return result; } export async function cancelAuthenticate() { if (!ExpoLocalAuthentication.cancelAuthenticate) { diff --git a/packages/expo-local-authentication/build/LocalAuthentication.js.map b/packages/expo-local-authentication/build/LocalAuthentication.js.map index ca5c5a31e4cea..b13502c6c046e 100644 --- a/packages/expo-local-authentication/build/LocalAuthentication.js.map +++ b/packages/expo-local-authentication/build/LocalAuthentication.js.map @@ -1 +1 @@ -{"version":3,"file":"LocalAuthentication.js","sourceRoot":"","sources":["../src/LocalAuthentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAEL,kBAAkB,GAEnB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAA8B,kBAAkB,EAA6B,CAAC;AAErF,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,uBAAuB,CAAC,gBAAgB,EAAE;QAC7C,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,EAAE,kBAAkB,CAAC,CAAC;KAChF;IACD,OAAO,MAAM,uBAAuB,CAAC,gBAAgB,EAAE,CAAC;AAC1D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iCAAiC;IACrD,IAAI,CAAC,uBAAuB,CAAC,iCAAiC,EAAE;QAC9D,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,EAAE,mCAAmC,CAAC,CAAC;KACjG;IACD,OAAO,MAAM,uBAAuB,CAAC,iCAAiC,EAAE,CAAC;AAC3E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,IAAI,CAAC,uBAAuB,CAAC,eAAe,EAAE;QAC5C,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,EAAE,iBAAiB,CAAC,CAAC;KAC/E;IACD,OAAO,MAAM,uBAAuB,CAAC,eAAe,EAAE,CAAC;AACzD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,UAAsC,EAAE;IAExC,IAAI,CAAC,uBAAuB,CAAC,iBAAiB,EAAE;QAC9C,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,EAAE,mBAAmB,CAAC,CAAC;KACjF;IAED,qDAAqD;IACrD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,CAAC,IAAI,CACV,2IAA2I,CAC5I,CAAC;QACF,OAAO,GAAG,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;KACtC;IAED,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE;QACzB,IAAI,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE;YAC3C,SAAS,CACP,OAAO,OAAO,CAAC,aAAa,KAAK,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,EACzE,6FAA6F,CAC9F,CAAC;SACH;QAED,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,cAAc,CAAC;QAC9D,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAAC,iBAAiB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;QAE9F,IAAI,MAAM,CAAC,OAAO,EAAE;YAClB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SAC9B;QACD,OAAO,MAAM,CAAC;KACf;SAAM;QACL,OAAO,MAAM,uBAAuB,CAAC,iBAAiB,EAAE,CAAC;KAC1D;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,CAAC,uBAAuB,CAAC,kBAAkB,EAAE;QAC/C,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,EAAE,oBAAoB,CAAC,CAAC;KAClF;IACD,MAAM,uBAAuB,CAAC,kBAAkB,EAAE,CAAC;AACrD,CAAC","sourcesContent":["import { UnavailabilityError } from '@unimodules/core';\nimport invariant from 'invariant';\nimport { Platform } from 'react-native';\n\nimport ExpoLocalAuthentication from './ExpoLocalAuthentication';\nimport {\n LocalAuthenticationOptions,\n AuthenticationType,\n LocalAuthenticationResult,\n} from './LocalAuthentication.types';\n\nexport { LocalAuthenticationOptions, AuthenticationType, LocalAuthenticationResult };\n\nexport async function hasHardwareAsync(): Promise {\n if (!ExpoLocalAuthentication.hasHardwareAsync) {\n throw new UnavailabilityError('expo-local-authentication', 'hasHardwareAsync');\n }\n return await ExpoLocalAuthentication.hasHardwareAsync();\n}\n\nexport async function supportedAuthenticationTypesAsync(): Promise {\n if (!ExpoLocalAuthentication.supportedAuthenticationTypesAsync) {\n throw new UnavailabilityError('expo-local-authentication', 'supportedAuthenticationTypesAsync');\n }\n return await ExpoLocalAuthentication.supportedAuthenticationTypesAsync();\n}\n\nexport async function isEnrolledAsync(): Promise {\n if (!ExpoLocalAuthentication.isEnrolledAsync) {\n throw new UnavailabilityError('expo-local-authentication', 'isEnrolledAsync');\n }\n return await ExpoLocalAuthentication.isEnrolledAsync();\n}\n\nexport async function authenticateAsync(\n options: LocalAuthenticationOptions = {}\n): Promise {\n if (!ExpoLocalAuthentication.authenticateAsync) {\n throw new UnavailabilityError('expo-local-authentication', 'authenticateAsync');\n }\n\n // Warn if using an old API - to be removed in SDK35.\n if (typeof options === 'string') {\n console.warn(\n 'String argument in LocalAuthentication.authenticateAsync has been deprecated. Please use options object with `promptMessage` key instead.'\n );\n options = { promptMessage: options };\n }\n\n if (Platform.OS === 'ios') {\n if (options.hasOwnProperty('promptMessage')) {\n invariant(\n typeof options.promptMessage === 'string' && options.promptMessage.length,\n 'LocalAuthentication.authenticateAsync : `options.promptMessage` must be a non-empty string.'\n );\n }\n\n const promptMessage = options.promptMessage || 'Authenticate';\n const result = await ExpoLocalAuthentication.authenticateAsync({ ...options, promptMessage });\n\n if (result.warning) {\n console.warn(result.warning);\n }\n return result;\n } else {\n return await ExpoLocalAuthentication.authenticateAsync();\n }\n}\n\nexport async function cancelAuthenticate(): Promise {\n if (!ExpoLocalAuthentication.cancelAuthenticate) {\n throw new UnavailabilityError('expo-local-authentication', 'cancelAuthenticate');\n }\n await ExpoLocalAuthentication.cancelAuthenticate();\n}\n"]} \ No newline at end of file +{"version":3,"file":"LocalAuthentication.js","sourceRoot":"","sources":["../src/LocalAuthentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAEL,kBAAkB,GAEnB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAA8B,kBAAkB,EAA6B,CAAC;AAErF,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,uBAAuB,CAAC,gBAAgB,EAAE;QAC7C,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,EAAE,kBAAkB,CAAC,CAAC;KAChF;IACD,OAAO,MAAM,uBAAuB,CAAC,gBAAgB,EAAE,CAAC;AAC1D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iCAAiC;IACrD,IAAI,CAAC,uBAAuB,CAAC,iCAAiC,EAAE;QAC9D,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,EAAE,mCAAmC,CAAC,CAAC;KACjG;IACD,OAAO,MAAM,uBAAuB,CAAC,iCAAiC,EAAE,CAAC;AAC3E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,IAAI,CAAC,uBAAuB,CAAC,eAAe,EAAE;QAC5C,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,EAAE,iBAAiB,CAAC,CAAC;KAC/E;IACD,OAAO,MAAM,uBAAuB,CAAC,eAAe,EAAE,CAAC;AACzD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,UAAsC,EAAE;IAExC,IAAI,CAAC,uBAAuB,CAAC,iBAAiB,EAAE;QAC9C,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,EAAE,mBAAmB,CAAC,CAAC;KACjF;IAED,qDAAqD;IACrD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,CAAC,IAAI,CACV,2IAA2I,CAC5I,CAAC;QACF,OAAO,GAAG,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;KACtC;IAED,IAAI,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE;QAC3C,SAAS,CACP,OAAO,OAAO,CAAC,aAAa,KAAK,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,EACzE,6FAA6F,CAC9F,CAAC;KACH;IAED,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,cAAc,CAAC;IAC9D,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAAC,iBAAiB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;IAE9F,IAAI,MAAM,CAAC,OAAO,EAAE;QAClB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;KAC9B;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,CAAC,uBAAuB,CAAC,kBAAkB,EAAE;QAC/C,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,EAAE,oBAAoB,CAAC,CAAC;KAClF;IACD,MAAM,uBAAuB,CAAC,kBAAkB,EAAE,CAAC;AACrD,CAAC","sourcesContent":["import { UnavailabilityError } from '@unimodules/core';\nimport invariant from 'invariant';\n\nimport ExpoLocalAuthentication from './ExpoLocalAuthentication';\nimport {\n LocalAuthenticationOptions,\n AuthenticationType,\n LocalAuthenticationResult,\n} from './LocalAuthentication.types';\n\nexport { LocalAuthenticationOptions, AuthenticationType, LocalAuthenticationResult };\n\nexport async function hasHardwareAsync(): Promise {\n if (!ExpoLocalAuthentication.hasHardwareAsync) {\n throw new UnavailabilityError('expo-local-authentication', 'hasHardwareAsync');\n }\n return await ExpoLocalAuthentication.hasHardwareAsync();\n}\n\nexport async function supportedAuthenticationTypesAsync(): Promise {\n if (!ExpoLocalAuthentication.supportedAuthenticationTypesAsync) {\n throw new UnavailabilityError('expo-local-authentication', 'supportedAuthenticationTypesAsync');\n }\n return await ExpoLocalAuthentication.supportedAuthenticationTypesAsync();\n}\n\nexport async function isEnrolledAsync(): Promise {\n if (!ExpoLocalAuthentication.isEnrolledAsync) {\n throw new UnavailabilityError('expo-local-authentication', 'isEnrolledAsync');\n }\n return await ExpoLocalAuthentication.isEnrolledAsync();\n}\n\nexport async function authenticateAsync(\n options: LocalAuthenticationOptions = {}\n): Promise {\n if (!ExpoLocalAuthentication.authenticateAsync) {\n throw new UnavailabilityError('expo-local-authentication', 'authenticateAsync');\n }\n\n // Warn if using an old API - to be removed in SDK35.\n if (typeof options === 'string') {\n console.warn(\n 'String argument in LocalAuthentication.authenticateAsync has been deprecated. Please use options object with `promptMessage` key instead.'\n );\n options = { promptMessage: options };\n }\n\n if (options.hasOwnProperty('promptMessage')) {\n invariant(\n typeof options.promptMessage === 'string' && options.promptMessage.length,\n 'LocalAuthentication.authenticateAsync : `options.promptMessage` must be a non-empty string.'\n );\n }\n\n const promptMessage = options.promptMessage || 'Authenticate';\n const result = await ExpoLocalAuthentication.authenticateAsync({ ...options, promptMessage });\n\n if (result.warning) {\n console.warn(result.warning);\n }\n return result;\n}\n\nexport async function cancelAuthenticate(): Promise {\n if (!ExpoLocalAuthentication.cancelAuthenticate) {\n throw new UnavailabilityError('expo-local-authentication', 'cancelAuthenticate');\n }\n await ExpoLocalAuthentication.cancelAuthenticate();\n}\n"]} \ No newline at end of file diff --git a/packages/expo-local-authentication/build/LocalAuthentication.types.d.ts b/packages/expo-local-authentication/build/LocalAuthentication.types.d.ts index 4732e603c39b2..17fa82db86625 100644 --- a/packages/expo-local-authentication/build/LocalAuthentication.types.d.ts +++ b/packages/expo-local-authentication/build/LocalAuthentication.types.d.ts @@ -11,6 +11,6 @@ export declare enum AuthenticationType { export declare type LocalAuthenticationOptions = { promptMessage?: string; cancelLabel?: string; - fallbackLabel?: string; disableDeviceFallback?: boolean; + fallbackLabel?: string; }; diff --git a/packages/expo-local-authentication/build/LocalAuthentication.types.js.map b/packages/expo-local-authentication/build/LocalAuthentication.types.js.map index c31dd6da610d4..e413ea04f6399 100644 --- a/packages/expo-local-authentication/build/LocalAuthentication.types.js.map +++ b/packages/expo-local-authentication/build/LocalAuthentication.types.js.map @@ -1 +1 @@ -{"version":3,"file":"LocalAuthentication.types.js","sourceRoot":"","sources":["../src/LocalAuthentication.types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,yEAAe,CAAA;IACf,uFAAsB,CAAA;AACxB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B","sourcesContent":["export type LocalAuthenticationResult = { success: true } | { success: false; error: string };\n\nexport enum AuthenticationType {\n FINGERPRINT = 1,\n FACIAL_RECOGNITION = 2,\n}\n\nexport type LocalAuthenticationOptions = {\n // iOS only\n promptMessage?: string;\n cancelLabel?: string;\n fallbackLabel?: string;\n disableDeviceFallback?: boolean;\n};\n"]} \ No newline at end of file +{"version":3,"file":"LocalAuthentication.types.js","sourceRoot":"","sources":["../src/LocalAuthentication.types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,yEAAe,CAAA;IACf,uFAAsB,CAAA;AACxB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B","sourcesContent":["export type LocalAuthenticationResult = { success: true } | { success: false; error: string };\n\nexport enum AuthenticationType {\n FINGERPRINT = 1,\n FACIAL_RECOGNITION = 2,\n}\n\nexport type LocalAuthenticationOptions = {\n promptMessage?: string;\n cancelLabel?: string;\n disableDeviceFallback?: boolean;\n // iOS only\n fallbackLabel?: string;\n};\n"]} \ No newline at end of file diff --git a/packages/expo-local-authentication/src/LocalAuthentication.ts b/packages/expo-local-authentication/src/LocalAuthentication.ts index 3c9098ffb4e03..40ae035de93a1 100644 --- a/packages/expo-local-authentication/src/LocalAuthentication.ts +++ b/packages/expo-local-authentication/src/LocalAuthentication.ts @@ -1,6 +1,5 @@ import { UnavailabilityError } from '@unimodules/core'; import invariant from 'invariant'; -import { Platform } from 'react-native'; import ExpoLocalAuthentication from './ExpoLocalAuthentication'; import { @@ -47,24 +46,20 @@ export async function authenticateAsync( options = { promptMessage: options }; } - if (Platform.OS === 'ios') { - if (options.hasOwnProperty('promptMessage')) { - invariant( - typeof options.promptMessage === 'string' && options.promptMessage.length, - 'LocalAuthentication.authenticateAsync : `options.promptMessage` must be a non-empty string.' - ); - } + if (options.hasOwnProperty('promptMessage')) { + invariant( + typeof options.promptMessage === 'string' && options.promptMessage.length, + 'LocalAuthentication.authenticateAsync : `options.promptMessage` must be a non-empty string.' + ); + } - const promptMessage = options.promptMessage || 'Authenticate'; - const result = await ExpoLocalAuthentication.authenticateAsync({ ...options, promptMessage }); + const promptMessage = options.promptMessage || 'Authenticate'; + const result = await ExpoLocalAuthentication.authenticateAsync({ ...options, promptMessage }); - if (result.warning) { - console.warn(result.warning); - } - return result; - } else { - return await ExpoLocalAuthentication.authenticateAsync(); + if (result.warning) { + console.warn(result.warning); } + return result; } export async function cancelAuthenticate(): Promise { diff --git a/packages/expo-local-authentication/src/LocalAuthentication.types.ts b/packages/expo-local-authentication/src/LocalAuthentication.types.ts index 28ef81d142429..52af52e131132 100644 --- a/packages/expo-local-authentication/src/LocalAuthentication.types.ts +++ b/packages/expo-local-authentication/src/LocalAuthentication.types.ts @@ -6,9 +6,9 @@ export enum AuthenticationType { } export type LocalAuthenticationOptions = { - // iOS only promptMessage?: string; cancelLabel?: string; - fallbackLabel?: string; disableDeviceFallback?: boolean; + // iOS only + fallbackLabel?: string; }; diff --git a/packages/expo-local-authentication/src/__tests__/LocalAuthentication-test.android.ts b/packages/expo-local-authentication/src/__tests__/LocalAuthentication-test.android.ts deleted file mode 100644 index f9fbc6af92bd2..0000000000000 --- a/packages/expo-local-authentication/src/__tests__/LocalAuthentication-test.android.ts +++ /dev/null @@ -1,15 +0,0 @@ -import ExpoLocalAuthentication from '../ExpoLocalAuthentication'; -import * as LocalAuthentication from '../LocalAuthentication'; - -beforeEach(() => { - ExpoLocalAuthentication.authenticateAsync.mockReset(); - ExpoLocalAuthentication.authenticateAsync.mockImplementation(async () => ({ success: true })); -}); - -it(`doesn't use a message on Android`, async () => { - await LocalAuthentication.authenticateAsync({ - promptMessage: 'Authentication is required', - }); - - expect(ExpoLocalAuthentication.authenticateAsync).toHaveBeenLastCalledWith(); -}); diff --git a/packages/expo-local-authentication/src/__tests__/LocalAuthentication-test.ios.ts b/packages/expo-local-authentication/src/__tests__/LocalAuthentication-test.native.ts similarity index 90% rename from packages/expo-local-authentication/src/__tests__/LocalAuthentication-test.ios.ts rename to packages/expo-local-authentication/src/__tests__/LocalAuthentication-test.native.ts index e16ce110b5ddb..73deeae75d6a2 100644 --- a/packages/expo-local-authentication/src/__tests__/LocalAuthentication-test.ios.ts +++ b/packages/expo-local-authentication/src/__tests__/LocalAuthentication-test.native.ts @@ -6,7 +6,7 @@ beforeEach(() => { ExpoLocalAuthentication.authenticateAsync.mockImplementation(async () => ({ success: true })); }); -it(`uses options on iOS`, async () => { +it(`uses options`, async () => { const options = { promptMessage: 'Authentication is required', cancelLabel: 'Abort', @@ -18,7 +18,7 @@ it(`uses options on iOS`, async () => { expect(ExpoLocalAuthentication.authenticateAsync).toHaveBeenLastCalledWith(options); }); -it(`throws when an invalid message is used on iOS`, async () => { +it(`throws when an invalid message is used`, async () => { expect( LocalAuthentication.authenticateAsync({ promptMessage: undefined as any }) ).rejects.toThrow();