Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Firebase onAuthStateChanged not called on expo reload #19

Open
dmolinae opened this issue Jan 7, 2019 · 3 comments
Open

Firebase onAuthStateChanged not called on expo reload #19

dmolinae opened this issue Jan 7, 2019 · 3 comments

Comments

@dmolinae
Copy link

dmolinae commented Jan 7, 2019

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
Copy link
Owner

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
Copy link
Author

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
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants