React-native-firebase: onAuthStateChanged not returning any result on iOS Sumulator

Created on 10 Nov 2018  路  10Comments  路  Source: invertase/react-native-firebase


Issue

I just updated to rnfirebase 5.1.0 from 5.0 and noticed that onAuthStateChanged works in a strange way on ios simulator. I need to reload app twice for the method to return a result. The first time I reload the app the callback is never invoked! Then after reloading again it works as expecred. If I reload again it does not work and it repeats.




Project Files






iOS

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
pod 'Firebase/Core', '~> 5.11.0'
pod 'Firebase/Auth', '~> 5.11.0'
pod 'Firebase/Firestore', '~> 5.11.0'
pod 'Firebase/Functions', '~> 5.11.0'
pod 'Firebase/Storage', '~> 5.11.0'
pod 'Firebase/Messaging', '~> 5.11.0'
pod 'Firebase/DynamicLinks', '~> 5.11.0'
# N/A

AppDelegate.m:

// N/A

Android

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->

Environment

  • Platform that you're experiencing the issue on:

    • [ ] iOS

    • [ ] Android

    • [x] iOS but have not tested behavior on Android

    • [ ] Android but have not tested behavior on iOS

    • [ ] Both

  • If known, the version of the platform are you experiencing the issue on:

    • iOS 12

  • Operating System:

    • [x] MacOS, version: 10.14

    • [ ] Windows, version: N/A

    • [ ] Other, please specify: N/A

  • Build Tools:

    • Xcode 10

  • React Native version:

    • 0.57.4

  • React Native Firebase library version:

    • 5.1

  • Firebase module(s) you're using that has the issue:

    • [ ] N/A

    • [x] Authentication

    • [ ] Analytics

    • [ ] Cloud Firestore

    • [ ] Cloud Messaging (FCM)

    • [ ] Crashlytics

    • [ ] Dynamic Links

    • [ ] Functions Callable

    • [ ] Invites

    • [ ] Instance ID

    • [ ] Notifications

    • [ ] Performance Monitoring

    • [ ] Realtime Database

    • [ ] Remote Config

    • [ ] Storage

  • Are you using TypeScript?

    • [x] No

    • [ ] Yes, version: N/A

  • Are you using Expo, e.g. ExpoKit?

    • [x] No

    • [ ] Yes, I've _not_ ejected

    • [ ] Yes, but I have ejected to ExpoKit

    • [ ] Yes, but I have ejected to vanilla React Native

    • Expo version: N/A




Think react-native-firebase is great? Please consider supporting the project with any of the below:

Needs Triage Authentication RN Reload

Most helpful comment

@ghsdh3409 just looked at your change and it makes sense - will get your PR merged for a patch release 馃憤

All 10 comments

I'm having the same issue. The first time I run the app onAuthStateChanged is triggered properly, If I refresh once, it won't return anything but If I refresh again, It works. And If do it one more time, It happens again and so on.

The same exact scenario is happening to me as outlined in the issue description and in @FacuAcosta 's comment. Same Firebase versions too.

happens to me too on iOS 12.1 simulator (RN 0.57.5, RNF 5.1.0)

onAuthStateChanged calls its callback every two reloads!

Is anyone having this issue on Android? Or is it just iOS?

Thanks

Happening to me on iOS as well after upgrading from 5.0 to 5.1, some additional info

Simulator (Debug)

  1. When I am not logged in at all it works every other reload (gets past initialisation stage)
  2. When I am logged in it works every time (perhaps from cache?) but if I trigger signOut it doesn't seem to trigger auth change, only after reloading

Physical Device (Release)
There seems to be an unusually long delay until onAuthChange is triggered / initialised, but it always works.

For my case, the following code makes onAuthStateChanged broken.

firebase.auth().signOut().then(() => { CodePush.restartApp(false) });

I checked that iOS native callback addAuthStateDidChangeListener is triggered. But, in the sendJSEvent, emitter.bridge is null. This is the reason that JS onAuthStateChanged is not triggered.

I make PR for this. Could you check if it resolves this issue?
You can install by modifying package.json like below.

"react-native-firebase": "git+https://github.com/hayanmind/react-native-firebase.git#1b5a9641383f1842d0a439109487c38903d1df2c"

@IljaDaderko @levani

@ghsdh3409 Yep, your fix works on my end 馃憤

@ghsdh3409 just looked at your change and it makes sense - will get your PR merged for a patch release 馃憤

Was this page helpful?
0 / 5 - 0 ratings