prescottprue / react-redux-firebase

Redux bindings for Firebase. Includes React Hooks and Higher Order Components.
https://react-redux-firebase.com
MIT License
2.55k stars 556 forks source link

bug(profile): onAuthStateChanged did not update user profile on react-native #689

Open MrHazimAli opened 5 years ago

MrHazimAli commented 5 years ago

Do you want to request a feature or report a bug?

bug

What is the current behavior?

User can use the app without login, but if the user login, they can see their profile data. after login, onAuthStateChanged is triggered, auth is updated with login user but profile still empty. this only occurring during sign in.. for sign out, user profile automatically cleared. the only way to get the profile right now is to kill the app and open it back. then profile is loaded inside redux store

Screen Shot 2019-04-22 at 3 26 21 PM

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via codesandbox or similar.

What is the expected behavior?

once user login, onAuthStateChanged is triggered and get the latest profile of the user during signout and sign in

Screen Shot 2019-04-22 at 3 28 06 PM

Which versions of dependencies, and which browser and OS are affected by this issue? Did this work in previous versions or setups?

tested on Google Pixel 2 Android 9 on debug mode Screen Shot 2019-04-22 at 3 47 53 PM

prescottprue commented 5 years ago

The profile loading is separate from auth loading. Auth is needed in order for the listener for profile data (which lives in users/:uid) to be attached. With that in mind, profile loading will always come after auth exists.

The onAuthStateChanged callback is where the profile listener is attached, but it should still be attached if the user is authenticated.

It could have to do with it being react-native-firebase instead of the Firebase JS SDK, but I don't use react-native-firebase often enough to know for sure. Can you provide a full code base where this can be reproduced?

MrHazimAli commented 5 years ago

hye @prescottprue , here is the repo to reproduce the issue

https://github.com/MrHazimAli/firebaseRepro

here is credential: email: hazimhis23@gmail.com pwd: 123456

illuminist commented 5 years ago

I still couldn't run your repro. But here's my speculation about the code

  1. You are not supposed to observe the props inside onAuthStateChanged. The listener is called when login, but props.profile still doesn't have actual profile because it need to get a data from firestore and it will be updated into redux state later. And you won't see the change because onAuthStateChanged is triggered only once when logged in, not when profile getting update.
  2. What are your redux dispatch actions? It should have SET_PROFILE after LOGIN.
  3. If number 2 is true, try to render profile inside a component this will surely show the current state of profile.
MrHazimAli commented 5 years ago

@illuminist ,

number 1 make sense.. but apparently, SET_PROFILE is only called after I kill the app and open it back. otherwise, after LOGIN, no redux dispatch actions are called.

Screen Shot 2019-04-26 at 10 10 17 AM ezgif com-video-to-gif

I clone it back to test the repo and it's running so far using this flow:

$ git clone https://github.com/MrHazimAli/firebaseRepro.git $ cd firebaseRepro $ yarn install $ cd ios $ pod install $ react-native run-ios

rajivxux commented 5 years ago

@prescottprue any updates on this? I have noticed that the firestore listeners too are impacted. They do not progress from SET_LISTENER to LISTENER_RESPONSE state. The peculiar thing is that if I let 10+ seconds pass between reloads the listeners and profile loading continue to function normally.