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

onAuthStateChange not working properly

Open itsmeek opened this issue 6 years ago • 3 comments

I freshly cloned this repo (Friday, Nov. 9, 2018) and added the following code to componentDidMount in the App.js file

async componentDidMount() {
    // TODO: You: Do firebase things
    // const { user } = await firebase.auth().signInAnonymously();
    // console.warn('User -> ', user.toJSON());

    // await firebase.analytics().logEvent('foo', { bar: '123'});

    ---> firebase.auth().onAuthStateChanged((user) => {
      console.log({ user });
    });
  }

There is a vital issue where the callback for onAuthStateChanged gets called every other time. On the first refresh, the callback gets invoked which logs the user. On the following refresh, the callback does not get invoked and the log does not get call. This cycles repeats for all subsequent refreshes

itsmeek avatar Nov 09 '18 16:11 itsmeek

Can you explain what you mean by "refreshes"?

Ehesp avatar Nov 10 '18 20:11 Ehesp

He used Command + R to refresh iOS simulator. On first refresh, onAuthStateChanged is triggered and there is a log from console.log({ user }); but if he refresh it again, this time onAuthStateChanged is not triggered and we can't see any log from console.log({ user });

kawin-impekable avatar Nov 10 '18 21:11 kawin-impekable

also having this issue

partriv avatar Jan 30 '19 05:01 partriv