onAuthStateChanged not triggered when user deleted or disabled in firebase console
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
- Application Target Platform: Both
- Development Operating System: macOS Sierra
- Build Tools: iOS SDK: 4.4.0, Android SDK: 11.4.2
- React Native version: 0.48.4
- RNFirebase Version: 3.0.5 (3.0.x to include timestamp bug fix)
- Firebase Module: auth
@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.
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.
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 ?
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