Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android onAuthStateChanged behavior does not match iOS and web #531

Closed
esamelson opened this issue Oct 19, 2017 · 10 comments
Closed

Android onAuthStateChanged behavior does not match iOS and web #531

esamelson opened this issue Oct 19, 2017 · 10 comments
Labels
Impact: Bug New bug report Impact: Web Implementation An API in RNFB does not conform to the Firebase Web SDK Platform: Android Service: Authentication Firebase Authentication Type: Firebase Issue or PR that addresses external Firebase behaviour issues or changes, e.g. a Firebase SDK issue Type: Stale Issue has become stale - automatically added by Stale bot

Comments

@esamelson
Copy link

esamelson commented Oct 19, 2017

Issue

I'm trying to use firebase.auth().onAuthStateChanged() to determine when a user's authentication has expired in the middle of using my app. The correct behavior according to Firebase's own JS SDK (which is replicated correctly for iOS in RNFirebase) is that as soon as authentication is no longer valid, the callback passed to onAuthStateChanged is called with null as its only parameter. On Android, however, the callback is simply never called. The user must close and restart the app to get the callback called with null.

Steps to replicate:

  1. Sign in on Android using signInWithEmailAndPassword
  2. Change Firebase password for that account
  3. Wait 60 mins for token to expire and auth to become invalid

Expected behavior (correct on iOS):
Callback previously passed to onAuthStateChanged is called with null

Actual behavior on Android:
onAuthStateChanged callback is not called. Instead, all database connections that require auth simply stop returning snapshots.

Environment

  1. Application Target Platform: Android
  1. Development Operating System: macOS Sierra
  1. Build Tools: Android Studio 2.3.3, Firebase Android SDK 11.4.2
  1. React Native version: 0.48.2
  1. RNFirebase Version: 3.0.4
  1. Firebase Module: auth
@chrisbianca
Copy link
Contributor

chrisbianca commented Oct 19, 2017

@esamelson Interesting scenario. Are you able to help us out by putting a break point in RNFirebaseAuth.java on line 88, i.e. inside the onAuthStateChanged listener:

FirebaseAuth.AuthStateListener newAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
          FirebaseUser user = firebaseAuth.getCurrentUser(); // ADD BREAKPOINT HERE
          WritableMap msgMap = Arguments.createMap();
          if (user != null) {
            msgMap.putBoolean("authenticated", true);
            msgMap.putString("appName", appName); // for js side distribution
            msgMap.putMap("user", firebaseUserToMap(user));
            Utils.sendEvent(mReactContext, "auth_state_changed", msgMap);
          } else {
            msgMap.putString("appName", appName); // for js side distribution
            msgMap.putBoolean("authenticated", false);
            Utils.sendEvent(mReactContext, "auth_state_changed", msgMap);
          }
        }
      };

This will tell us whether it's a Firebase SDK issue or something wrong with RNFirebase.

Obviously, if this doesn't fire after 60 minutes then it's something that should be reported to Firebase. If it does, then we can investigate where the issue might be in our code...

@esamelson esamelson reopened this Oct 19, 2017
@esamelson
Copy link
Author

esamelson commented Oct 19, 2017

Sure, I can't do this right now, but I should be able to get to it sometime in the next few days.

@chrisbianca
Copy link
Contributor

Great, no rush!

@Salakar Salakar added Platform: Android Service: Authentication Firebase Authentication Impact: Bug New bug report Type: Firebase Issue or PR that addresses external Firebase behaviour issues or changes, e.g. a Firebase SDK issue Impact: Web Implementation An API in RNFB does not conform to the Firebase Web SDK labels Oct 21, 2017
@chrisbianca chrisbianca added the Workflow: Waiting for User Response Blocked waiting for user response. label Oct 23, 2017
@Ehesp
Copy link
Member

Ehesp commented Nov 3, 2017

@esamelson did you manage to check this out?

@chrisbianca
Copy link
Contributor

@esamelson I tried this out on Friday by doing the following:

  1. Logging the user in
  2. Changing their password through the console
  3. Waiting for onAuthStateChanged to fire on both iOS and Android by adding breakpoints in the native code.

Several hours later and it still hadn't fired.

I then repeated by deleting the user from the console rather than changing their password, and the same happened - no update by onAuthStateChanged at all.

This does seem like it's a Firebase issue, though I'm interested in the fact that you saw iOS update. How did you change the user's password?

@esamelson
Copy link
Author

@chrisbianca - sorry I wasn't able to get to this as quickly as I'd hoped. Interesting to hear that you weren't able to reproduce the behavior I saw on iOS. I consistently saw onAuthStateChanged fire with a null value after about an hour, on both iOS and web (JS SDK). I was changing the password programmatically by using the web SDK's user.updatePassword method on my own webpage (separate from the app I was testing).

@Salakar Salakar removed the Workflow: Waiting for User Response Blocked waiting for user response. label Jun 26, 2018
@keshavkaul
Copy link

keshavkaul commented Aug 13, 2018

@Ehesp On iOS, I'm facing an issue where onAuthStateChanged is not called when signing in using signInAndRetrieveDataWithEmailAndPassword?

Edit
Sorry, I was incorrectly using rxjs to observe the changes. All good here.

@stale
Copy link

stale bot commented Sep 10, 2018

Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Sep 10, 2018
@stale
Copy link

stale bot commented Sep 24, 2018

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Sep 24, 2018
@cjpete
Copy link

cjpete commented Mar 6, 2020

I'm seeing this on iOS, whilst using react-native-firebase version 5.5.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impact: Bug New bug report Impact: Web Implementation An API in RNFB does not conform to the Firebase Web SDK Platform: Android Service: Authentication Firebase Authentication Type: Firebase Issue or PR that addresses external Firebase behaviour issues or changes, e.g. a Firebase SDK issue Type: Stale Issue has become stale - automatically added by Stale bot
Projects
None yet
Development

No branches or pull requests

6 participants