From 587cab8910d4f5ba4c21c063cce2959563d0919a Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 19 Nov 2024 09:43:29 +0200 Subject: [PATCH 01/10] feat: introduced `autoOTPVerify` for Android devices --- .../auth/ReactNativeFirebaseAuthModule.java | 15 ++++++----- packages/auth/lib/PhoneAuthListener.js | 5 +++- packages/auth/lib/Settings.js | 9 +++++++ packages/auth/lib/index.d.ts | 27 +++++++++++++++++++ packages/auth/lib/index.js | 5 ++-- 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java index 06c73c7698..103dda6186 100644 --- a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java +++ b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java @@ -981,7 +981,7 @@ private void signInWithProvider(String appName, ReadableMap provider, final Prom */ @ReactMethod public void signInWithPhoneNumber( - String appName, final String phoneNumber, final boolean forceResend, final Promise promise) { + String appName, final String phoneNumber, final boolean forceResend, final Promise promise, final boolean autoOTPVerify) { Log.d(TAG, "signInWithPhoneNumber"); FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp); @@ -1080,10 +1080,10 @@ public void onCodeAutoRetrievalTimeOut(String verificationId) { if (forceResend && mForceResendingToken != null) { PhoneAuthProvider.getInstance(firebaseAuth) .verifyPhoneNumber( - phoneNumber, 60, TimeUnit.SECONDS, activity, callbacks, mForceResendingToken); + phoneNumber, autoOTPVerify ? 60 : 0, TimeUnit.SECONDS, activity, callbacks, mForceResendingToken); } else { PhoneAuthProvider.getInstance(firebaseAuth) - .verifyPhoneNumber(phoneNumber, 60, TimeUnit.SECONDS, activity, callbacks); + .verifyPhoneNumber(phoneNumber, autoOTPVerify ? 60 : 0, TimeUnit.SECONDS, activity, callbacks); } } } @@ -1113,7 +1113,7 @@ public void getSession(final String appName, final Promise promise) { @ReactMethod public void verifyPhoneNumberWithMultiFactorInfo( - final String appName, final String hintUid, final String sessionKey, final Promise promise) { + final String appName, final String hintUid, final String sessionKey, final Promise promise, final boolean autoOTPVerify) { final MultiFactorResolver resolver = mCachedResolvers.get(sessionKey); if (resolver == null) { // See https://firebase.google.com/docs/reference/node/firebase.auth.multifactorresolver for @@ -1153,7 +1153,7 @@ public void verifyPhoneNumberWithMultiFactorInfo( PhoneAuthOptions.newBuilder(firebaseAuth) .setActivity(activity) .setMultiFactorHint((PhoneMultiFactorInfo) selectedHint) - .setTimeout(30L, TimeUnit.SECONDS) + .setTimeout(autoOTPVerify ? 30L : 0L, TimeUnit.SECONDS) .setMultiFactorSession(resolver.getSession()) .setCallbacks( new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { @@ -1185,7 +1185,8 @@ public void verifyPhoneNumberForMultiFactor( final String appName, final String phoneNumber, final String sessionKey, - final Promise promise) { + final Promise promise, + final boolean autoOTPVerify) { final MultiFactorSession multiFactorSession = mMultiFactorSessions.get(sessionKey); if (multiFactorSession == null) { rejectPromiseWithCodeAndMessage( @@ -1198,7 +1199,7 @@ public void verifyPhoneNumberForMultiFactor( PhoneAuthOptions.newBuilder(firebaseAuth) .setPhoneNumber(phoneNumber) .setActivity(getCurrentActivity()) - .setTimeout(30L, TimeUnit.SECONDS) + .setTimeout(autoOTPVerify ? 30L : 0L, TimeUnit.SECONDS) .setMultiFactorSession(multiFactorSession) .requireSmsValidation(true) .setCallbacks( diff --git a/packages/auth/lib/PhoneAuthListener.js b/packages/auth/lib/PhoneAuthListener.js index 9d5378a7f0..f21ad222c9 100644 --- a/packages/auth/lib/PhoneAuthListener.js +++ b/packages/auth/lib/PhoneAuthListener.js @@ -21,12 +21,13 @@ import NativeFirebaseError from '@react-native-firebase/app/lib/internal/NativeF let REQUEST_ID = 0; export default class PhoneAuthListener { - constructor(auth, phoneNumber, timeout, forceResend) { + constructor(auth, phoneNumber, timeout, forceResend, autoOTPVerify) { this._auth = auth; this._reject = null; this._resolve = null; this._promise = null; this._jsStack = new Error().stack; + this._autoOTPVerify = autoOTPVerify this._timeout = timeout || 20; this._phoneAuthRequestId = REQUEST_ID++; @@ -50,11 +51,13 @@ export default class PhoneAuthListener { this._subscribeToEvents(); if (isAndroid) { + this._auth. this._auth.native.verifyPhoneNumber( phoneNumber, this._phoneAuthRequestId + '', this._timeout, this._forceResending, + this._autoOTPVerify ); } diff --git a/packages/auth/lib/Settings.js b/packages/auth/lib/Settings.js index 4ed5e3c2fc..02b765916c 100644 --- a/packages/auth/lib/Settings.js +++ b/packages/auth/lib/Settings.js @@ -22,12 +22,21 @@ export default class Settings { this._auth = auth; this._forceRecaptchaFlowForTesting = false; this._appVerificationDisabledForTesting = false; + this._autoOTPVerify = true; /* Android only */ } get forceRecaptchaFlowForTesting() { return this._forceRecaptchaFlowForTesting; } + get autoOTPVerify() { + return this._autoOTPVerify; + } + + set autoOTPVerify(autoOTPVerify) { + this._autoOTPVerify = autoOTPVerify; + } + set forceRecaptchaFlowForTesting(forceRecaptchaFlow) { if (isAndroid) { this._forceRecaptchaFlowForTesting = forceRecaptchaFlow; diff --git a/packages/auth/lib/index.d.ts b/packages/auth/lib/index.d.ts index 3ba68f2e91..22f01c95a7 100644 --- a/packages/auth/lib/index.d.ts +++ b/packages/auth/lib/index.d.ts @@ -1116,6 +1116,33 @@ export namespace FirebaseAuthTypes { * @param smsCode The pre-set SMS code. */ setAutoRetrievedSmsCodeForPhoneNumber(phoneNumber: string, smsCode: string): Promise; + + /** + * Flag to disable automatic retrieval of SMS codes for the given phone number. + * When receiving a verification code Android automagically digests the OTP code, + * in some cases this can cause issues like "OTP already used". + * Use it only if absolutely necessary. + * + * @android + */ + autoOTPVerify: boolean; + + /** + * Sets whether the automatic OTP (One-Time Password) verification should be disabled on Android devices. + * + * This method allows you to control the behavior of OTP verification by disabling the automatic retrieval + * and verification of SMS codes. This can be useful in testing scenarios or when you want to handle OTP + * verification manually if your users encounter "OTP already used" errors on some devices. + * + * @example + * ```js + * await firebase.auth().settings.setAutoOTPVerify(false); + * ``` + * + * @android + * @param status whether auto OTP verify should be disabled, defaults to false + */ + setAutoOTPVerify(status: boolean): Promise; } /** diff --git a/packages/auth/lib/index.js b/packages/auth/lib/index.js index 0cc488d6c8..493ccda8fe 100644 --- a/packages/auth/lib/index.js +++ b/packages/auth/lib/index.js @@ -282,7 +282,7 @@ class FirebaseAuthModule extends FirebaseModule { signInWithPhoneNumber(phoneNumber, forceResend) { if (isAndroid) { return this.native - .signInWithPhoneNumber(phoneNumber, forceResend || false) + .signInWithPhoneNumber(phoneNumber, forceResend || false, this._settings.autoOTPVerify) .then(result => new ConfirmationResult(this, result.verificationId)); } @@ -294,6 +294,7 @@ class FirebaseAuthModule extends FirebaseModule { verifyPhoneNumber(phoneNumber, autoVerifyTimeoutOrForceResend, forceResend) { let _forceResend = forceResend; let _autoVerifyTimeout = 60; + let _autoOTPVerify = this._settings.autoOTPVerify if (isBoolean(autoVerifyTimeoutOrForceResend)) { _forceResend = autoVerifyTimeoutOrForceResend; @@ -301,7 +302,7 @@ class FirebaseAuthModule extends FirebaseModule { _autoVerifyTimeout = autoVerifyTimeoutOrForceResend; } - return new PhoneAuthListener(this, phoneNumber, _autoVerifyTimeout, _forceResend); + return new PhoneAuthListener(this, phoneNumber, _autoVerifyTimeout, _forceResend, _autoOTPVerify); } verifyPhoneNumberWithMultiFactorInfo(multiFactorHint, session) { From c9274fb41aec1e1e16d4f9ea54219cc72b2ace04 Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 19 Nov 2024 09:52:08 +0200 Subject: [PATCH 02/10] fix: remove set from setAutoOTPVerify from Settings.js --- packages/auth/lib/Settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/auth/lib/Settings.js b/packages/auth/lib/Settings.js index 02b765916c..f0754831c6 100644 --- a/packages/auth/lib/Settings.js +++ b/packages/auth/lib/Settings.js @@ -33,7 +33,7 @@ export default class Settings { return this._autoOTPVerify; } - set autoOTPVerify(autoOTPVerify) { + setAutoOTPVerify(autoOTPVerify) { this._autoOTPVerify = autoOTPVerify; } From b1fcae8c9a876e680e861bd627e991555c7f958f Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 19 Nov 2024 09:53:23 +0200 Subject: [PATCH 03/10] fix: remove duplicate line on PhoneAuthListener.js :face_palm: --- packages/auth/lib/PhoneAuthListener.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/auth/lib/PhoneAuthListener.js b/packages/auth/lib/PhoneAuthListener.js index f21ad222c9..4bbd62edf4 100644 --- a/packages/auth/lib/PhoneAuthListener.js +++ b/packages/auth/lib/PhoneAuthListener.js @@ -51,7 +51,6 @@ export default class PhoneAuthListener { this._subscribeToEvents(); if (isAndroid) { - this._auth. this._auth.native.verifyPhoneNumber( phoneNumber, this._phoneAuthRequestId + '', From 670f2ed73f2269e3a2a9c5b0390aa9a226d98345 Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 19 Nov 2024 10:26:40 +0200 Subject: [PATCH 04/10] docs: updated phone-auth.md, added autoOTPVerify --- docs/auth/phone-auth.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/auth/phone-auth.md b/docs/auth/phone-auth.md index fbe501ac15..40319ffabd 100644 --- a/docs/auth/phone-auth.md +++ b/docs/auth/phone-auth.md @@ -227,3 +227,33 @@ export default function PhoneVerification() { } } ``` + +# Disabling automatic OTP verification on Android devices + +Firebase Auth automagically verifies the received OTP code from the SMS and in some certain devices it might throw `The SMS code has expired` error. + +Disable auto verify by adding this on `index.js` or `App.tsx`: + +```jsx +await firebase.auth().settings.setAutoOTPVerify(false); +``` + +To manually handle OTP verification code: + +```jsx +// set code and phone from textinputs +const [phone, setPhone] = useState(''); +const [code, setCode] = useState(''); + +const handlePhoneLogin = async () => { + try { + const confirmResult = await auth().signInWithPhoneNumber(phone); + + await confirmResult.confirm(code).then(user => { + console.log(user); + }); + } catch (e) { + console.log(e); + } +}; +``` From dcfadaee84cd4a9b3b5da529aafc05d94a6d1f1d Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 19 Nov 2024 10:31:28 +0200 Subject: [PATCH 05/10] chore: improved settings example on index.d.ts --- packages/auth/lib/index.d.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/auth/lib/index.d.ts b/packages/auth/lib/index.d.ts index 22f01c95a7..7a150ca55a 100644 --- a/packages/auth/lib/index.d.ts +++ b/packages/auth/lib/index.d.ts @@ -1120,7 +1120,7 @@ export namespace FirebaseAuthTypes { /** * Flag to disable automatic retrieval of SMS codes for the given phone number. * When receiving a verification code Android automagically digests the OTP code, - * in some cases this can cause issues like "OTP already used". + * in some cases this can cause issues like `The SMS code has expired`. * Use it only if absolutely necessary. * * @android @@ -1132,11 +1132,18 @@ export namespace FirebaseAuthTypes { * * This method allows you to control the behavior of OTP verification by disabling the automatic retrieval * and verification of SMS codes. This can be useful in testing scenarios or when you want to handle OTP - * verification manually if your users encounter "OTP already used" errors on some devices. + * verification manually if your users encounter `The SMS code has expired` errors on some devices. * * @example * ```js - * await firebase.auth().settings.setAutoOTPVerify(false); + * (async function () { + * try { + * await firebase.auth().settings.setAutoOTPVerify(false); + * } catch (error) { + * console.error(error); + * } + * })(); + * * ``` * * @android From 5600693b83c79523e28deaa743de39641277373c Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 19 Nov 2024 10:31:51 +0200 Subject: [PATCH 06/10] chore: improved settings example phone-auth.md --- docs/auth/phone-auth.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/auth/phone-auth.md b/docs/auth/phone-auth.md index 40319ffabd..058e1b5bb6 100644 --- a/docs/auth/phone-auth.md +++ b/docs/auth/phone-auth.md @@ -235,7 +235,13 @@ Firebase Auth automagically verifies the received OTP code from the SMS and in s Disable auto verify by adding this on `index.js` or `App.tsx`: ```jsx -await firebase.auth().settings.setAutoOTPVerify(false); +(async function () { + try { + await firebase.auth().settings.setAutoOTPVerify(false); + } catch (error) { + console.error(error); + } +})(); ``` To manually handle OTP verification code: From c85eab95f6fd62dc8b0c66cc090ea10819042d7b Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 19 Nov 2024 10:35:48 +0200 Subject: [PATCH 07/10] chore: renamed status to enabled on setAutoOTPVerify types --- packages/auth/lib/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/auth/lib/index.d.ts b/packages/auth/lib/index.d.ts index 7a150ca55a..87a05d28b2 100644 --- a/packages/auth/lib/index.d.ts +++ b/packages/auth/lib/index.d.ts @@ -1147,9 +1147,9 @@ export namespace FirebaseAuthTypes { * ``` * * @android - * @param status whether auto OTP verify should be disabled, defaults to false + * @param enabled whether auto OTP verify should be disabled, defaults to false */ - setAutoOTPVerify(status: boolean): Promise; + setAutoOTPVerify(enabled: boolean): Promise; } /** From 32540d88a91b24a7871684f1247713013fd68cdd Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 19 Nov 2024 10:48:55 +0200 Subject: [PATCH 08/10] chore: lint --- .../auth/ReactNativeFirebaseAuthModule.java | 22 +++++++++++++++---- packages/auth/lib/PhoneAuthListener.js | 4 ++-- packages/auth/lib/index.js | 10 +++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java index 103dda6186..b8c2293144 100644 --- a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java +++ b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java @@ -981,7 +981,11 @@ private void signInWithProvider(String appName, ReadableMap provider, final Prom */ @ReactMethod public void signInWithPhoneNumber( - String appName, final String phoneNumber, final boolean forceResend, final Promise promise, final boolean autoOTPVerify) { + String appName, + final String phoneNumber, + final boolean forceResend, + final Promise promise, + final boolean autoOTPVerify) { Log.d(TAG, "signInWithPhoneNumber"); FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp); @@ -1080,10 +1084,16 @@ public void onCodeAutoRetrievalTimeOut(String verificationId) { if (forceResend && mForceResendingToken != null) { PhoneAuthProvider.getInstance(firebaseAuth) .verifyPhoneNumber( - phoneNumber, autoOTPVerify ? 60 : 0, TimeUnit.SECONDS, activity, callbacks, mForceResendingToken); + phoneNumber, + autoOTPVerify ? 60 : 0, + TimeUnit.SECONDS, + activity, + callbacks, + mForceResendingToken); } else { PhoneAuthProvider.getInstance(firebaseAuth) - .verifyPhoneNumber(phoneNumber, autoOTPVerify ? 60 : 0, TimeUnit.SECONDS, activity, callbacks); + .verifyPhoneNumber( + phoneNumber, autoOTPVerify ? 60 : 0, TimeUnit.SECONDS, activity, callbacks); } } } @@ -1113,7 +1123,11 @@ public void getSession(final String appName, final Promise promise) { @ReactMethod public void verifyPhoneNumberWithMultiFactorInfo( - final String appName, final String hintUid, final String sessionKey, final Promise promise, final boolean autoOTPVerify) { + final String appName, + final String hintUid, + final String sessionKey, + final Promise promise, + final boolean autoOTPVerify) { final MultiFactorResolver resolver = mCachedResolvers.get(sessionKey); if (resolver == null) { // See https://firebase.google.com/docs/reference/node/firebase.auth.multifactorresolver for diff --git a/packages/auth/lib/PhoneAuthListener.js b/packages/auth/lib/PhoneAuthListener.js index 4bbd62edf4..a455321951 100644 --- a/packages/auth/lib/PhoneAuthListener.js +++ b/packages/auth/lib/PhoneAuthListener.js @@ -27,7 +27,7 @@ export default class PhoneAuthListener { this._resolve = null; this._promise = null; this._jsStack = new Error().stack; - this._autoOTPVerify = autoOTPVerify + this._autoOTPVerify = autoOTPVerify; this._timeout = timeout || 20; this._phoneAuthRequestId = REQUEST_ID++; @@ -56,7 +56,7 @@ export default class PhoneAuthListener { this._phoneAuthRequestId + '', this._timeout, this._forceResending, - this._autoOTPVerify + this._autoOTPVerify, ); } diff --git a/packages/auth/lib/index.js b/packages/auth/lib/index.js index 493ccda8fe..1f6ad93d08 100644 --- a/packages/auth/lib/index.js +++ b/packages/auth/lib/index.js @@ -294,7 +294,7 @@ class FirebaseAuthModule extends FirebaseModule { verifyPhoneNumber(phoneNumber, autoVerifyTimeoutOrForceResend, forceResend) { let _forceResend = forceResend; let _autoVerifyTimeout = 60; - let _autoOTPVerify = this._settings.autoOTPVerify + let _autoOTPVerify = this._settings.autoOTPVerify; if (isBoolean(autoVerifyTimeoutOrForceResend)) { _forceResend = autoVerifyTimeoutOrForceResend; @@ -302,7 +302,13 @@ class FirebaseAuthModule extends FirebaseModule { _autoVerifyTimeout = autoVerifyTimeoutOrForceResend; } - return new PhoneAuthListener(this, phoneNumber, _autoVerifyTimeout, _forceResend, _autoOTPVerify); + return new PhoneAuthListener( + this, + phoneNumber, + _autoVerifyTimeout, + _forceResend, + _autoOTPVerify, + ); } verifyPhoneNumberWithMultiFactorInfo(multiFactorHint, session) { From 57fb8720719ab83ea7c58c5cd2b8b9f06b2439d0 Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 19 Nov 2024 10:56:14 +0200 Subject: [PATCH 09/10] chore: minor jsDoc language improvements on types --- packages/auth/lib/index.d.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/auth/lib/index.d.ts b/packages/auth/lib/index.d.ts index 87a05d28b2..cded0e748b 100644 --- a/packages/auth/lib/index.d.ts +++ b/packages/auth/lib/index.d.ts @@ -1118,10 +1118,9 @@ export namespace FirebaseAuthTypes { setAutoRetrievedSmsCodeForPhoneNumber(phoneNumber: string, smsCode: string): Promise; /** - * Flag to disable automatic retrieval of SMS codes for the given phone number. - * When receiving a verification code Android automagically digests the OTP code, - * in some cases this can cause issues like `The SMS code has expired`. - * Use it only if absolutely necessary. + * Flag to disable automatic retrieval of OTP codes for the given phone number. + * When receiving an OTP verification code Android automagically digests it and + * in some cases throws this error: `The SMS code has expired` * * @android */ @@ -1132,7 +1131,7 @@ export namespace FirebaseAuthTypes { * * This method allows you to control the behavior of OTP verification by disabling the automatic retrieval * and verification of SMS codes. This can be useful in testing scenarios or when you want to handle OTP - * verification manually if your users encounter `The SMS code has expired` errors on some devices. + * verification manually if your users encounter `The SMS code has expired` error on some devices. * * @example * ```js From 5a96645834f01afab3f1ce83b394752cd18b918f Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 19 Nov 2024 12:19:47 +0200 Subject: [PATCH 10/10] fix: pass autoOTPVerify only to necessary functions --- .../auth/ReactNativeFirebaseAuthModule.java | 14 +++++++------ packages/auth/lib/PhoneAuthListener.js | 4 +--- packages/auth/lib/index.js | 21 ++++++++++--------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java index b8c2293144..db1ce355b9 100644 --- a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java +++ b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java @@ -984,8 +984,8 @@ public void signInWithPhoneNumber( String appName, final String phoneNumber, final boolean forceResend, - final Promise promise, - final boolean autoOTPVerify) { + final boolean autoOTPVerify, + final Promise promise) { Log.d(TAG, "signInWithPhoneNumber"); FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp); @@ -1126,8 +1126,9 @@ public void verifyPhoneNumberWithMultiFactorInfo( final String appName, final String hintUid, final String sessionKey, - final Promise promise, - final boolean autoOTPVerify) { + final boolean autoOTPVerify, + final Promise promise + ) { final MultiFactorResolver resolver = mCachedResolvers.get(sessionKey); if (resolver == null) { // See https://firebase.google.com/docs/reference/node/firebase.auth.multifactorresolver for @@ -1199,8 +1200,9 @@ public void verifyPhoneNumberForMultiFactor( final String appName, final String phoneNumber, final String sessionKey, - final Promise promise, - final boolean autoOTPVerify) { + final boolean autoOTPVerify, + final Promise promise + ) { final MultiFactorSession multiFactorSession = mMultiFactorSessions.get(sessionKey); if (multiFactorSession == null) { rejectPromiseWithCodeAndMessage( diff --git a/packages/auth/lib/PhoneAuthListener.js b/packages/auth/lib/PhoneAuthListener.js index a455321951..9d5378a7f0 100644 --- a/packages/auth/lib/PhoneAuthListener.js +++ b/packages/auth/lib/PhoneAuthListener.js @@ -21,13 +21,12 @@ import NativeFirebaseError from '@react-native-firebase/app/lib/internal/NativeF let REQUEST_ID = 0; export default class PhoneAuthListener { - constructor(auth, phoneNumber, timeout, forceResend, autoOTPVerify) { + constructor(auth, phoneNumber, timeout, forceResend) { this._auth = auth; this._reject = null; this._resolve = null; this._promise = null; this._jsStack = new Error().stack; - this._autoOTPVerify = autoOTPVerify; this._timeout = timeout || 20; this._phoneAuthRequestId = REQUEST_ID++; @@ -56,7 +55,6 @@ export default class PhoneAuthListener { this._phoneAuthRequestId + '', this._timeout, this._forceResending, - this._autoOTPVerify, ); } diff --git a/packages/auth/lib/index.js b/packages/auth/lib/index.js index 1f6ad93d08..ad59b58dbd 100644 --- a/packages/auth/lib/index.js +++ b/packages/auth/lib/index.js @@ -294,7 +294,6 @@ class FirebaseAuthModule extends FirebaseModule { verifyPhoneNumber(phoneNumber, autoVerifyTimeoutOrForceResend, forceResend) { let _forceResend = forceResend; let _autoVerifyTimeout = 60; - let _autoOTPVerify = this._settings.autoOTPVerify; if (isBoolean(autoVerifyTimeoutOrForceResend)) { _forceResend = autoVerifyTimeoutOrForceResend; @@ -302,22 +301,24 @@ class FirebaseAuthModule extends FirebaseModule { _autoVerifyTimeout = autoVerifyTimeoutOrForceResend; } - return new PhoneAuthListener( - this, - phoneNumber, - _autoVerifyTimeout, - _forceResend, - _autoOTPVerify, - ); + return new PhoneAuthListener(this, phoneNumber, _autoVerifyTimeout, _forceResend); } verifyPhoneNumberWithMultiFactorInfo(multiFactorHint, session) { - return this.native.verifyPhoneNumberWithMultiFactorInfo(multiFactorHint.uid, session); + return this.native.verifyPhoneNumberWithMultiFactorInfo( + multiFactorHint.uid, + session, + this._settings.autoOTPVerify, + ); } verifyPhoneNumberForMultiFactor(phoneInfoOptions) { const { phoneNumber, session } = phoneInfoOptions; - return this.native.verifyPhoneNumberForMultiFactor(phoneNumber, session); + return this.native.verifyPhoneNumberForMultiFactor( + phoneNumber, + session, + this._settings.autoOTPVerify, + ); } resolveMultiFactorSignIn(session, verificationId, verificationCode) {