McD
McD

Reputation: 173

Firebase Auth Persistance in React Native

I'm using Firebase email + pw sign in for my React Native application, but the login doesn't seem to persist after the app is closed and reopened. I read in the documentation that the default is to persist, so I'm not sure why it's not behaving that way?

I'm using the following on componentWillMount:

this.state.dbh.auth().onAuthStateChanged(function(user) {
        if (user) {
            this.state = {
                user: user
            }
        }

I'm also using Expo to develop - would this have an effect on persisting the login?

Upvotes: 1

Views: 1305

Answers (1)

phusick
phusick

Reputation: 7352

This is a regression introduced in Firebase v4.5.1 as described here.

Solution:

  1. Downgrade to Firebase v4.5.0
  2. Restart Expo with npm start -- --reset-cache

Edit:

The issue is fixed in Firebase v4.5.2.

  1. Upgrade to Firebase v4.5.2
  2. Change Firebase import

    // from
    import * as firebase from 'firebase/app';
    import 'firebase/auth';
    
    // to
    import firebase from 'firebase';
    

As described here.

Upvotes: 3

Related Questions