问题
When a user comes to my site, I use onAuthStateChanged
to determine if the user is already signed-in from a previous session or not.
Main issue is that it has been inconsistent for a small % of users - code seems to not be detecting that they do have a valid signed-in session going on.
The following code is on the app itself, users are on that page after a redirect from the homepage or login page.
The homepage of the site also uses onAuthStateChanged
to determine if the user should be redirected to the app directly. The login page uses signInWithEmailAndPassword and when the log in is successful, redirects them to the app page (which has the following code).
firebase.auth().onAuthStateChanged(function (authUser) {
if (authUser) return initApp(authUser);
// issue: sometimes users that *should* be signed-in get signed in anonymously here
firebase.auth().signInAnonymously().then(function (authUser) {
initApp(authUser);
}
});
Is onAuthStateChanged
just not something I should be using for my use case? Any idea how to improve / fix this?
Edit: This SEEMS to happen more with users on mobiles.
来源:https://stackoverflow.com/questions/39395158/onauthstatechanged-inconsistent