firebase js sdk auth and react native - login state does not persist on app restart

714 views
Skip to first unread message

Florian Norbert Bepunkt

unread,
Nov 17, 2016, 12:54:40 PM11/17/16
to Firebase Google Group
Summary:
User's auth state does not persist on app restart.

My situation:
I have a blank react native app (current react native version, fresh install) and installed firebase js sdk via

react-native init firebaseTest
npm i firebase
--save


in my index.ios.js file I added a auth state listener and a login function

constructor(props) {
   
super(props);
 
   
this.state = {};


    firebase
.auth().onAuthStateChanged(function(user) {
     
if (user) {
        console
.log('user logged in: ', user);
     
} else {
        console
.log('not logged in…');
     
}
   
});
 
}


  login
() {
    firebase
.auth().signInWithEmailAndPassword('te...@test.com', 'test123')
     
.catch((error) => {
        console
.log('Error: ', error.message);
     
});
 
}


Login works, however if I restart, user object is null… By restart I mean closing the app on simulator and then reopen it.

Is this intended behaviour? I read (I think in this group) that user status persists. 

Thanks,
Florian

Florian Norbert Bepunkt

unread,
Nov 17, 2016, 3:46:03 PM11/17/16
to Firebase Google Group
Okay, it seems I'm not the only one. This issue seems related to new react-native version 0.37.0 - https://github.com/facebook/react-native/issues/10958

José Urbano Duarte Junior

unread,
Nov 17, 2016, 6:31:42 PM11/17/16
to Firebase Google Group
On my project, this issue occurs only on iOS.

Florian Norbert Bepunkt

unread,
Nov 18, 2016, 8:17:55 AM11/18/16
to Firebase Google Group
I checked with the upcoming react-native 0.38.rc-0 … same behaviour on ios. auth state is not saved. tested with clean install

Bassam

unread,
Nov 18, 2016, 3:19:10 PM11/18/16
to Firebase Google Group
Hey all, the react native sdk doesn't do anything fancy to store state on the device. It just uses asyncStorage which is the recommended way for mobile apps built with react native.
I am not sure why you are experiencing this. Can you try testing by manually setting data in asyncStorage and then restart the device and check the data is still there? Last time I checked, i was not able to reproduce this.

Florian Norbert Bepunkt

unread,
Nov 18, 2016, 3:38:10 PM11/18/16
to Firebase Google Group
I will try to test this on the weekend.

Have you tested with the current react-native version (0.37.0)?

It's strange, I can reproduce this on two maschines by creating a new react-native project, installing firebase, and login to one of my firebase projects with a user I created in dashboard.

I can upload a simple test case if this is of any help. but in my initial message I posted all code i added to default react native project besides my firebase config data.

Channing Huang

unread,
Nov 18, 2016, 10:56:08 PM11/18/16
to Firebase Google Group
Do you happen to be using "Debug JS remotely"?

Florian Norbert Bepunkt

unread,
Nov 19, 2016, 8:23:04 AM11/19/16
to Firebase Google Group
Saw your post on github… Yes, I'm using "Debug JS remotely"

Avishay Bar

unread,
Nov 22, 2016, 11:02:28 AM11/22/16
to Firebase Google Group
Same happens here on 0.37.0.

Hector Ramos

unread,
Nov 22, 2016, 6:08:51 PM11/22/16
to Firebase Google Group
A fix has landed in master and should ship as part React Native 0.39. You can try it out today on master, or in the 0.39 Release Candidate shortly.

Kristofer Eng

unread,
Nov 29, 2016, 2:31:48 PM11/29/16
to Firebase Google Group
+1 - just ran into this issue as well. Guess no auto logging in until it is fixed.


On Thursday, November 17, 2016 at 9:54:40 AM UTC-8, Florian Norbert Bepunkt wrote:

Bassam

unread,
Nov 29, 2016, 2:39:01 PM11/29/16
to Firebase Google Group
Hey all, this should be fixed in version 3.6.2:
Reply all
Reply to author
Forward
0 new messages