EvanBacon / expo-native-firebase

🔥 Native Firebase Expo App (iOS, Android) Demo for Firestore, Notifications, Analytics, Storage, Messaging, Database 🚨
211 stars 41 forks source link

Firebase onAuthStateChanged not called on expo reload #19

Open dmolinae opened 5 years ago

dmolinae commented 5 years ago

I can use all firebase SDKs without problems.

I call onAuthStateChanged like so in my app.

import firebase from 'expo-firebase-app'

export default class LoadingScreen extends React.Component {
  componentDidMount() {
    this._unsubscribe = firebase.auth().onAuthStateChanged(user => {
      setTimeout(() => {
        this.props.navigation.navigate(user ? 'Main' : 'Introduction'); //Welcome / Introduction
      }, 1500)
    });
  }
  componentWillUnmount() {
    this._unsubscribe();
  }
}

When I first start up the app, the callback in onAuthStateChanged triggered fine. However, if I do a reload of the app by saving any file inside the proyect, it doesn't call the callback anymore.

If I close and reopen the app, then it works again.

EvanBacon commented 5 years ago

it works on every other reload, this is because RN is only calling dealloc every-other reload. Working on a fix but it's a hack around RN

dmolinae commented 5 years ago

Finally, I use a temporary solution by importing the Firebase Web SDK for the .auth() class...

Working without problems.

Like this:

import * as firebase from 'firebase';
import firestore from 'firebase/firestore'

const settings = {timestampsInSnapshots: true};

const config = { [firebaseConfig] }

firebase.initializeApp(config);

firebase.firestore().settings(settings);

onAuthStateChanged = (callback) => {
  firebase.auth().onAuthStateChanged(callback);
}
benfontan commented 5 years ago

I'm having the same issue which is really annoying during development. I'd like to avoid importing Web SDK. Can you share your fix @EvanBacon? Even if that's a workaround. Thanks a lot in advance.