代码之家  ›  专栏  ›  技术社区  ›  Michel

使用firebase.auth()时出现问题。onAuthStateChanged accross两页

  •  0
  • Michel  · 技术社区  · 5 年前

    我有一个小问题,有两个html页面,在过去的工作。

    首先,我有一个登录页面(login.html),其中包含以下代码:

    firebase.auth().onAuthStateChanged(function(user) {
      if (user) {
        // User is signed in.
        window.open("main.html",'_self');
      } else {
        // No user is signed in.
        prompt for login ....
        ......
      }
    });
    

    firebase.auth().onAuthStateChanged(function(user) {
      if (user) {
        // User is signed in.
        do serious work ....
        ......
      } else {
        // Let us double check:
        let theUser = firebase.auth().currentUser;
    
        if (!theUser) {
            // No user is signed in.
            window.open("login.html",'_self');
        }
        // We need some patience :)
        ......
      }
    });
    

    一旦用户登录,就应该转到main.html;这就是它过去的工作原理。但现在,不知什么原因;当我登录时,即使我已经提供了我的凭据,流也会转到main.html(正如它应该的那样),但会立即返回到login.html。

    我已经能够检查块(在main.html中):

    firebase.auth().onAuthStateChanged(function(user) {...}
    

    未检测到我已登录。为什么呢?

    附笔。

    0 回复  |  直到 5 年前
        1
  •  0
  •   user12419448 user12419448    5 年前

    我遇到了同样的问题。我把范围缩小到铬合金。它似乎认为Chrome在保存cookies时是不允许的(我检查了设置)。最近的Chrome更新可能有问题?作为一个理智的检查,在Firefox上尝试一下,让我知道这是否有效。对我来说是这样的。

    {code: "auth/web-storage-unsupported", message: "This browser is not 
    supported or 3rd party cookies and data may be disabled.", a: null}