This function is triggered by clicking the Login button:
export const loginUser = ({ email, password }) => {
return (dispatch) => {
dispatch({ type: LOGIN_USER });
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then(() => {
firebase.auth().signInWithEmailAndPassword(email, password)
.then(user => {
firebase.database().ref('/admins').once('value')
.then(snapshot => {
const admins = _.map(snapshot.val(), (val, uid) => {
return { ...val, uid };
});
if (admins.some((item) => item.s_email === email)) {
typeAdmin(dispatch);
} else typeStudent(dispatch);
loginUserSuccess(dispatch, user);
});
}).catch(() => loginUserFail(dispatch));
});
};
};
Current Behavior
When you exit the application and back you need to relogar to access currentUser data.
Expected Behavior
When leaving the application keep the currentUser of the session and when nothing back has been lost.