onAuthStateChanged inconsistent

二次信任 提交于 2019-12-10 02:19:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!