I have not been able to persist a firebase session in my react-native application. This question is nearly identical to React Native - Firebase auth persistence not working but the answer provided there has not worked for me.
Currently I log in as shown below:
export const loginUser = ({ email, password }) => {
return (dispatch) => {
dispatch({ type: LOGIN_USER });
firebase.auth().signInWithEmailAndPassword(email, password)
.then(user => loginUserSuccess(dispatch, user))
.catch(() => loginUserFailed(dispatch))
};
};
My session is created and I have access to the user object stored on firebase.
When I Cmd+R or when I close the application and reopen it my session is gone. I have run the following in the componentWillMount() section of my app.js file:
firebase.auth().onAuthStateChanged((user) => {
if (user) {
console.log('user is logged');
} else {
console.log('not logged in')
}
});
Whenever I refresh the app or close it completely and reopen I get the 'not logged in' response.
I have also tried querying:
firebase.auth().currentUser
but get the same issue where it returns null
What am I doing wrong?
Is there a particular way to keep the session active that I am missing?