invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.68k stars 2.21k forks source link

firebase.auth().signInWithPhoneNumber() returns null verificationId on android #2895

Closed hadare1 closed 4 years ago

hadare1 commented 4 years ago

Hi, after I try to sign in with phone number in my android the object that returns is :

Screen Shot 2019-11-18 at 22 46 06

on iOS it looks better :

Screen Shot 2019-11-18 at 22 49 10

later when I try to user .confirm(code) I get this crash :

Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, ortemprary proof.

this is my code:

async getConfirmationCode(phoneNumber) {
    try {
        confirm = await firebase.auth().signInWithPhoneNumber(phoneNumber,true);
        console.log(confirm)
        runInAction(() => {
            this.confirmResult = confirm;
        })
    } catch (e) {
        if (e.message) modalCompatibleAlert("Error",e.message);
        else modalCompatibleAlert(e)
    }
}

then I confirm the code here:

confirmCode = flow(function* (codeInput, callback) {
    if (this.confirmResult && codeInput.length) {
        try {
            const result = yield this.confirmResult.confirm(codeInput);
            if (user._user.email !== null) { // user exists
                this.userExists = true;
            }
        } catch (e) {
            callback(false);
        }
    }
});

this is my package.json file:

Click To Expand { "name": "Jesta", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest", "build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'" }, "dependencies": { "@babel/plugin-proposal-decorators": "^7.4.0", "@ishawnwang/withunmounted": "^1.0.1", "@react-native-community/async-storage": "^1.3.3", "audit": "0.0.6", "axios": "^0.19.0", "babel-plugin-transform-decorators-legacy": "^1.3.5", "babel-preset-es2015": "^6.24.1", "bugsnag-react-native": "^2.23.1", "eject": "0.0.4", "email-validator": "^2.0.4", "firebase": "^5.9.2", "fix": "0.0.6", "jetifier": "^1.6.3", "lodash": "^4.17.15", "mobx": "^5.9.4", "mobx-react": "^5.4.3", "phone-formatter": "0.0.2", "pubnub": "^4.24.6", "pubnub-react": "^1.3.1", "react": "16.8.3", "react-native": "^0.60.4", "react-native-animatable": "^1.3.2", "react-native-app-settings": "^2.0.1", "react-native-appearance": "^0.1.0", "react-native-camera": "^2.6.0", "react-native-check-box": "^2.1.7", "react-native-clean-project": "^3.2.4", "react-native-country-picker-modal": "^0.8.0", "react-native-device-info": "^1.6.1", "react-native-elements": "^1.1.0", "react-native-firebase": "^5.3.1", "react-native-flash-message": "^0.1.13", "react-native-gesture-handler": "^1.3.0", "react-native-haptic": "^1.0.1", "react-native-haptic-feedback": "^1.8.0", "react-native-icon-badge": "^1.1.3", "react-native-ignore-warnings": "^0.1.1", "react-native-image-view": "^2.1.4", "react-native-image-zoom-viewer": "^2.2.26", "react-native-keyboard-aware-scroll-view": "^0.8.0", "react-native-light": "^1.0.8", "react-native-loading-spinner-overlay": "^1.0.1", "react-native-mail": "^3.0.7", "react-native-modal": "^9.0.0", "react-native-notifications": "^2.0.6", "react-native-onesignal": "^3.3.0", "react-native-permissions": "^1.1.1", "react-native-pin-code": "^0.5.3", "react-native-push-notification": "^3.1.3", "react-native-qrcode-scanner": "^1.1.2", "react-native-safe-area": "^0.5.1", "react-native-section-list-get-item-layout": "^2.2.3", "react-native-segmented-control-tab": "^3.4.0", "react-native-splash-screen": "^3.2.0", "react-native-swipeout": "^2.3.6", "react-native-torch": "^1.1.5", "react-native-vector-icons": "^6.6.0", "react-navigation": "^3.6.1", "react-navigation-transitions": "^1.0.10", "rn-sliding-up-panel": "^2.2.0", "tipsi-stripe": "^7.5.1" }, "devDependencies": { "@babel/core": "7.4.3", "@babel/runtime": "7.4.3", "babel-jest": "24.7.0", "babel-plugin-transform-remove-console": "^6.9.4", "babel-preset-mobx": "^2.0.0", "jest": "24.7.0", "metro-react-native-babel-preset": "0.53.1", "react-test-renderer": "16.8.3" }, "jest": { "preset": "react-native" } }

Android

Click To Expand

#### `android/settings.gradle`: rootProject.name = 'appname' include ':bugsnag-react-native' project(':bugsnag-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/bugsnag-react-native/android') include ':react-native-mail' project(':react-native-mail').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mail/android') include ':react-native-camera' project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') include ':react-native-torch' project(':react-native-torch').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-torch/android') include ':tipsi-stripe' project(':tipsi-stripe').projectDir = new File(rootProject.projectDir, '../node_modules/tipsi-stripe/android') include ':RNMail', ':app' project(':RNMail').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mail/android') include ':reactnativenotifications' project(':reactnativenotifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notifications/android/app') include ':@react-native-community_async-storage' project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android') include ':react-native-haptic-feedback' project(':react-native-haptic-feedback').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-haptic-feedback/android') include ':react-native-app-settings' project(':react-native-app-settings').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-app-settings/android') include ':react-native-splash-screen' project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android') include ':react-native-app-settings' project(':react-native-app-settings').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-app-settings/android') include ':react-native-device-info' project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android') include ':react-native-firebase' project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android') include ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android') include ':react-native-gesture-handler' project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android') include ':app' ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` ```xml ```


Environment

Click To Expand

**`react-native info` output:** info Fetching system and libraries information... System: OS: macOS 10.14.6 CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz Memory: 23.68 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.16.3 - /usr/local/bin/node npm: 6.9.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 Android SDK: API Levels: 23, 26, 27, 28, 29 Build Tools: 28.0.3, 29.0.2 System Images: android-28 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom IDEs: Android Studio: 3.5 AI-191.8026.42.35.5791312 Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild npmPackages: react: 16.8.3 => 16.8.3 react-native: ^0.60.4 => 0.60.4 - **Platform that you're experiencing the issue on**: - [ ] iOS - [X] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - 5.3.1 - **Are you using `TypeScript`?** - `N`

mikehardy commented 4 years ago

I hate to say this - but with version v5.3 I have no idea. Especially since it seems you've already made the jump to react-native 0.60.x you might try moving to the tip of the v5.x.x branch (that will be v5.5.6 plus a couple patches for react-native >0.60 that aren't released as v5.5.7 yet) and the current firebase android bom (24.0.2 I think?). It might integrate easily, then you'd know whether it was happening on current versions so we could troubleshoot better

hadare1 commented 4 years ago

unfortunately I tried to update react-native-firebase to 5.5.6 and I updated all my firebase android bom according to this : https://firebase.google.com/support/release-notes/android

But I get the same result. it's only working on either iOS or on a test phone number that I declared on the firebase console..

I don't know if it's related or not but I when I try to signInWithPhoneNumber again I do not receive new verification code as SMS.

mikehardy commented 4 years ago

I'm really sorry that didn't help, but at least you are current now so any fix will actually be possible for you. There are a couple other issues in the repo right now about this in v6 I think - you might search for them to see if there is commonality as I think auth was a pretty straight port from v5 to v6. Also, I'm not sure if it is possible but have tried a code flow that relies on the listeners for auth state changing vs the direct results?

Eralyne commented 4 years ago

I have this same problem. It's causing a lot of trouble as most Android devices aren't able to register/login to our app in release. I personally have an auth state change listener and it does not resolve the problem. Am currently using v6.0.1

For some reason Samsung Galaxy S8 phones do not have this issue at all. I don't know about any other android devices in specifics, though.

mikehardy commented 4 years ago

Well I am strike 2 on that one then, dang. We're on mostly current versions (RNFB v5 isn't current but as mentioned I believe the code is a straight port to RNFBv6, but the android SDKs are current). Doesn't seem to matter between the listener or the direct response. @Salakar @Ehesp these seems like some sort real module phone sign-in difference between Android and iOS. I think it has some related issues logged against v6 as well, might be 3 issues for one at this point if you can take a look

whenmoon commented 4 years ago

Confirmed that I am having this issue too. When trying to sign in with RNFB v6 and RN v0.61.4 the verificationId is null and I get the error cannot create phone auth credential without either verificationproof sessioninfo ortemprary proof.

whenmoon commented 4 years ago

I've now downgraded to RNFB v ~5.5.6 but have pulled in the 5 commits that have been added to it since release, and still running RN version 0.61.4.

Unfortunately the problem persists where verificationId returns null:

Screenshot 2019-11-23 at 16 20 40

My code is as follows:

import firebase from 'react-native-firebase';

export const authorizeFirebase = phoneNumber => {
  console.log('authorizeFirebase CALLED');
  console.log(phoneNumber);
  return new Promise((res, rej) => {
    firebase.auth()
      .verifyPhoneNumber(phoneNumber)
      .on('state_changed', async phoneAuthSnapshot => {
        switch (phoneAuthSnapshot.state) {

          case firebase.auth.PhoneAuthState.AUTO_VERIFIED: // or 'verified'
            const { verificationId, code } = phoneAuthSnapshot;
            console.log(verificationId);
            const accessToken = await confirmCode(verificationId, code);
            res(accessToken);
            break;

          case firebase.auth.PhoneAuthState.CODE_SENT: // or 'sent'
            res(phoneAuthSnapshot)
            break;

          case firebase.auth.PhoneAuthState.AUTO_VERIFY_TIMEOUT: // or 'timeout'
            res(phoneAuthSnapshot)
            break;

          case firebase.auth.PhoneAuthState.ERROR: // or 'error'
            rej(phoneAuthSnapshot)
            break;
        }
      }, (error) => {
        console.log(error);
      });
  })
}

Does anyone know what the last version of RN that works with RNFB Phone Number Auth is? Thanks.

whenmoon commented 4 years ago

All issues are resolved for me now that I've just tried running the app on a physical device I'm running the most recent versions of RN and RNFB with phone auth and obtaining authorisation using a Pixel 2XL.

My mistake was that I had been developing previously using an AVD logging in using an account that had already been created. So I hadn't needed to make these auth calls which require a physical device

vietmobilefolk commented 4 years ago

I also have issue, some days ago. Before, verificationId, code were not null when auto_verify in Android. But now everything except state are null. { verificationId: null, code: null, error: null, state: 'verified' }

bars0um commented 4 years ago

This seems to have been an issue for us specifically when we used a real phone number with the whitelisting on firebase console. Apparently you are meant to use 'fictional' numbers only, for us the specific number we used for testing was actually one of our devs, his number is now forever in FB limbo, we can't seem to recover it even after removing it from the test list. If we use other numbers it works fine (https://firebase.google.com/docs/auth/ios/phone-auth#test-with-whitelisted-phone-numbers).

mikehardy commented 4 years ago

Oh wow, that sounds frustrating. Maybe open a doc request with them to emphasize it should be fictitious numbers only e.g. +1xxx555xxxx - google is a bit quiet about doc requests but they work there way through I think

stale[bot] commented 4 years ago

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

bars0um commented 4 years ago

I’ve found that when user backgrounds the app to get the code from their messaging app, on returning, the confirmation object might have been destroyed, putting it in my redux store seems to have helped...

B

On 16 Jan 2020, at 17:04, Luis notifications@github.com wrote:

 Same issue here

My code:

const confirmResult = await auth().signInWithPhoneNumber(phone) this.setState({ step: STEPS.CODE, confirmResult, isFetching: false })

    try {
      const user = await confirmResult.confirm(code)
      console.log('_onSubmitCode user: ', user)
    } catch (e) {
      console.log('_onSubmitCode error: ', e)
    }

Log console.log('_onSubmitCode user: ', user) is printed, but app crash (In android native code, because i execute it on javascript try catch)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

stale[bot] commented 4 years ago

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

MarvynORourke commented 4 years ago

Hello ! Same issue here I can no longer receive the code and SMS with android but the verification works correctly when I use test numbers and when I request the code with IOS.

Has anyone come up with a solution?

luisfuertes commented 4 years ago

+1

I dont receive phone code sms, but it continue to sms code step. If i submit wrong code, app crash.

Versions:

    "react": "16.9.0",
    "react-native": "0.61.5",
    "@react-native-firebase/app": "^6.3.4",
    "@react-native-firebase/auth": "^6.3.4",
    "@react-native-firebase/messaging": "^6.3.4",

Android google services

classpath 'com.google.gms:google-services:4.2.0'

Logcat:

FATAL EXCEPTION: mqt_native_modules
Process: com.my_app, PID: 10856
java.lang.IllegalArgumentException: Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof, or enrollment ID.
    at com.google.android.gms.common.internal.Preconditions.checkArgument(Unknown Source:35)
    at com.google.firebase.auth.PhoneAuthCredential.<init>(com.google.firebase:firebase-auth@@19.1.0:7)
    at com.google.firebase.auth.PhoneAuthProvider.getCredential(com.google.firebase:firebase-auth@@19.1.0:33)
    at io.invertase.firebase.auth.ReactNativeFirebaseAuthModule.confirmationResultConfirm(ReactNativeFirebaseAuthModule.java:945)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:371)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150)
    at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26)
    at android.os.Looper.loop(Looper.java:207)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225)
    at java.lang.Thread.run(Thread.java:764)

Javascript auth code:

_onSubmitPhone = (phone, country) => {
    this.setState({ isFetching: true, phone, country }, async () => {
      try {
        const confirmResult = await auth().signInWithPhoneNumber(phone)
        console.log('_onSubmitPhone confirmResult: ', confirmResult)
        this.setState({ step: STEPS.CODE, confirmResult, isFetching: false })
      } catch (e) {
        console.log('_onSubmitPhone error: ', e)
        Alert.alert('Error', _.get(e, 'message', 'Ha ocurrido un error'))
        this.setState({ isFetching: false })
      }
    })
  }

  _onSubmitCode = code => {
    const { confirmResult } = this.state
    if (confirmResult && code) {
      this.setState({ isFetching: true, code }, async () => {
        try {
          const user = await confirmResult.confirm(code)
          console.log('_onSubmitCode user: ', user)
          this.setState({ step: STEPS.PASSWORD, user, isFetching: false })
        } catch (e) {
          console.log('_onSubmitCode error: ', e)
          Alert.alert('Error', _.get(e, 'message', 'Ha ocurrido un error'))
          this.setState({ isFetching: false })
        }
      })
    }
  }
Ehesp commented 4 years ago

Scanned this issue but didn't see it - have you ensured the debug SHA has been entered and added to the config files download from the firebase console?

luisfuertes commented 4 years ago

@Ehesp Yes, in debug one time i had received sms, but not now. And when i submit bad sms code (because i didnt receive it), app crash with adb logcat posted error.

I have app open now in debug mode. Do you need me to do some checking?

Ehesp commented 4 years ago

If you could log out the variables & share inside of this method, it'd be super handy: https://github.com/invertase/react-native-firebase/blob/master/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java#L1378

luisfuertes commented 4 years ago

Now with other phone number, i receive sms code. With bad sms code app only show error alert (Its ok) and with correct sms code all works fine.

But with my phone number, i dont receive sms code and on bad sms code submit app crash xd

Is a mistery

EDIT: Wait, i check that method logs

luisfuertes commented 4 years ago

UPDATE: Im thinking that last correct try with other phone number different than my, phone number submited was a iphone. (i was checked in android)

Maybe in my android phone i received a silent push and im not checking the auth state with listener. And after i received silenced push im trying to submit some sms code. But phone are validate already.... and app crash.

explained me well?

EDIT: if i submit my phone, i receive user in onAuthStateChanged (With android silent push). App crash when u have a user logged and try to submit code (This issue).

With this info app doesnt show code form if "confirmResult._verificationId" is null (Android), and wait to onAuthStateChanged event update. If "confirmResult._verificationId" is not null, i show code form and all work fine.

mikehardy commented 4 years ago

The original issue here was a v5.x problem with null verificationId, but @luisfuertes you are reporting a crash vs v6. Perhaps a separate issue?

luisfuertes commented 4 years ago

@mikehardy I dont think are seaparate issue.

verificationId only come null when android phone number is verified by silent push. And in that case u dont receive sms and if you try to submit sms code (invent or wrong code) app crash.

wongjiahau commented 4 years ago

I'm on "react-native-firebase": "^5.5.6", using Android, after I call verifyPhoneNumber, I got authSnapshot as {"code": null, "error": null, "state": "verified", "verificationId": null}.

That phone number I use works on iOS, however when I use it on Android this problem happens. If I'm not mistaken this is related to Instant Verification, as mentioned here https://stackoverflow.com/a/48906032/6587634

Update: I found the solution here https://github.com/invertase/react-native-firebase/issues/1962#issuecomment-521990883

nolann-dev commented 4 years ago

hey guy i found this. This is Instant Verification (https://stackoverflow.com/a/48906032) that mean Some Android devices may automatically verify codes received via SMS. try onAuthStateChanged to get user. https://invertase.io/oss/react-native-firebase/v6/auth/phone-auth on rnfirebase v6

firebase.auth().onAuthStateChanged(user => {
  if (user) {
    // Stop the login flow / Navigate to next page
  }
});
akash2237778 commented 4 years ago

I'm facing the same issue, generated on unity with firebase sdk version 6.13.0 . Even tried on physical android device. Everything else is working great (Token is generated successfully).

russellwheatley commented 4 years ago

I've switched this to a version 6 issue as we no longer support version 5 issues.

MuhammadUsman786786 commented 4 years ago

I am still facing this issue does anyone has to find the issue on the latest release on react native firebase? "@react-native-firebase/auth": "^8.0.4",

ovidiumunteanu commented 4 years ago

Hi. I am also getting those issues. I realized it's from ' instant-verification, Auto-retrieval'. There is no enough information on that in the react-native firebase documentation. I tried using onAuthStateChanged but every number gets user information. What is the best way to get this approach?

mikehardy commented 4 years ago

PRs to documentation happily accepted!

Ehesp commented 4 years ago

Can someone sumarize the exact issue here? Are things working or a lack of docs?

suretarget commented 4 years ago

Can someone sumarize the exact issue here? Are things working or a lack of docs?

I have tested with 3 different android phone. One of my phone perform an instant verification as I stated in this issue.

Ehesp commented 4 years ago

I think the signInWithPhoneNumber implementation is confusing here. Personally I'd stick with using verifyPhoneNumber and pass the credential to signInWithCredential. I'll take a look at seeing how we can improve the docs.

stale[bot] commented 4 years ago

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

judygab commented 4 years ago

hey guy i found this. This is Instant Verification (https://stackoverflow.com/a/48906032) that mean Some Android devices may automatically verify codes received via SMS. try onAuthStateChanged to get user. https://invertase.io/oss/react-native-firebase/v6/auth/phone-auth on rnfirebase v6

firebase.auth().onAuthStateChanged(user => {
  if (user) {
    // Stop the login flow / Navigate to next page
  }
});

Can you provide the code also including your sign up method please? I've been trying to solve this issue for so long it would be helpful!

mikehardy commented 4 years ago

@judygab https://rnfirebase.io/auth/usage#listening-to-authentication-state

Or, this the old APIs but auth works roughly the same, here is a class-based example https://v5.rnfirebase.io/docs/v5.x.x/auth/phone-auth - especially the example here https://v5.rnfirebase.io/docs/v5.x.x/auth/phone-auth#verifyPhoneNumber

mikehardy commented 4 years ago

If anyone wants to propose a PR to the docs, we will happily merge it, but I don't think there is anything else actionable here

ahron1 commented 3 years ago

If anyone wants to propose a PR to the docs, we will happily merge it, but I don't think there is anything else actionable here

Stumbled upon this myself; if this is still relevant, I can append a small note to the docs in the coming days.