react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

onAuthStateChanged not triggered when user deleted or disabled in firebase console

Open gazgeek opened this issue 9 years ago • 4 comments

Issue

I've got my app working with firebase.auth().onAuthStateChanged() and I'm able to create users with emails and passwords and log in as expected. I can also explicitly logout with firebase.auth().signOut().

However, I when I disable or delete the user in the Authentication panel in the firebase UI the firebase.auth().onAuthStateChanged() isn't called.

Would you expect firebase.auth().onAuthStateChanged() to be called or am I missing some other way to force a re-login after such a change?

Environment

  1. Application Target Platform: Both
  2. Development Operating System: macOS Sierra
  3. Build Tools: iOS SDK: 4.4.0, Android SDK: 11.4.2
  4. React Native version: 0.48.4
  5. RNFirebase Version: 3.0.5 (3.0.x to include timestamp bug fix)
  6. Firebase Module: auth

gazgeek avatar Oct 24 '17 15:10 gazgeek

@gazgeek Sorry to be the bearer or bad news, but unfortunately this is by design, as explained here by one of the Firebase engineers: https://stackoverflow.com/a/35961217/5909648

It looks like there's two ways of tackling this:

  • Wait for the current token to expire - there is another issue open waiting to confirm whether this works correctly in RNFirebase: https://github.com/invertase/react-native-firebase/issues/531
  • Manually add a /users/ part to your database which can be used in your security rules, although this won't log the user out, it will just prevent access to protected resources.

chrisbianca avatar Oct 26 '17 07:10 chrisbianca

Might be too late, but another work around that might be more useful is to include something like this .catch((err)=>{ if(err){ if(err.code === "PERMISSION_DENIED"){ //CLEAR ASYNC AND LOGOUT } } }) at any of your firebase calls.

fufuninja avatar Feb 25 '19 09:02 fufuninja

or can we do something like this .. like I set a users/{user_id}/signout = true into database and get the value into app with .on listener something like

firebase.database().ref('users/{user_id}/signout').on('value', value => { 
 if ( value.val() !== null && value.val() === true ){ 
firebase.auth().signOut();
Actions.root()
}
})

? is it a good way to perform this ?

amitbravo avatar Apr 04 '19 07:04 amitbravo

that was one of the proposed solutions in the stack overflow set of answers yes - you can do a global area and listen on the client

security enforced on the client isn't what you want though if you are worried about onAuth in the client not being called, as the client can't be trusted. doing something on the server either with extra security rules, or doing a custom token so you can invalidate all on the server is the only way to provably cut off access immediately if I understand things

mikehardy avatar Apr 04 '19 13:04 mikehardy