Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase注销用户所有会话_Javascript_Ios_Swift_Firebase - Fatal编程技术网

Javascript Firebase注销用户所有会话

Javascript Firebase注销用户所有会话,javascript,ios,swift,firebase,Javascript,Ios,Swift,Firebase,我正在iOS应用程序中使用Firebase身份验证。当用户使用Firebase登录我的应用程序,然后注销该用户的所有其他设备(会话)时,Firebase中是否有任何方法?我可以用Firebase admin SDK做到这一点吗?Firebase不提供此类功能。你需要自己管理它 这里是最新版本,他们没有提到任何与单用户登录相关的内容 以下是您可以为此做的事情- 在Firebase数据库中的用户节点(保存用户其他数据的位置)中获取一个令牌,并在每次登录应用程序时重新生成它,将此令牌与已登录的用户令牌

我正在iOS应用程序中使用Firebase身份验证。当用户使用Firebase登录我的应用程序,然后注销该用户的所有其他设备(会话)时,Firebase中是否有任何方法?我可以用Firebase admin SDK做到这一点吗?

Firebase
不提供此类功能。你需要自己管理它

这里是最新版本,他们没有提到任何与单用户登录相关的内容

以下是您可以为此做的事情-


Firebase
数据库中的用户节点(保存用户其他数据的位置)中获取一个令牌,并在每次登录应用程序时重新生成它,将此令牌与已登录的用户令牌(保存在本地)匹配在
appDidBecomeActive
appDidFinishLaunching
中,或者每次使用
Firebase执行任何操作时,或者可能在某个固定时间间隔内。如果令牌不同,则用户手动注销并将用户带到身份验证屏幕。

Firebase
不提供此类功能。你需要自己管理它

这里是最新版本,他们没有提到任何与单用户登录相关的内容

以下是您可以为此做的事情-


Firebase
数据库中的用户节点(保存用户其他数据的位置)中获取一个令牌,并在每次登录应用程序时重新生成它,将此令牌与已登录的用户令牌(保存在本地)匹配在
appDidBecomeActive
appDidFinishLaunching
中,或者每次使用
Firebase执行任何操作时,或者可能在某个固定时间间隔内。如果令牌不同,则用户手动注销并将用户带到身份验证屏幕。

当我遇到此问题时,我使用云功能解决了它 有关更多详细信息,请访问此链接

执行以下操作

  • 使用firebase云功能设置web服务器(如果不存在)
  • 使用管理员APK(这是此方法唯一有效的方法)-[访问此链接]( ()
  • 创建一个api,该api接收uid并按照上面第一个链接中的指定撤销当前会话

  • 瞧,用户注销了。我希望这能让我深入了解如何解决这个问题。当我遇到这个问题时,我用云功能解决了它 有关更多详细信息,请访问此链接

    执行以下操作

  • 使用firebase云功能设置web服务器(如果不存在)
  • 使用管理员APK(这是此方法唯一有效的方法)-[访问此链接]( ()
  • 创建一个api,该api接收uid并按照上面第一个链接中的指定撤销当前会话
  • 瞧,用户已注销。我希望这能帮助您深入了解问题的解决方法。我所做的是:

    在firestore中创建了名为“activeSessions”的集合。用户电子邮件作为对象的id,而“activeID”字段用于保存最近的会话id

    在登录页面代码中:

    每次用户登录时生成用户会话的id。 将此id添加到localstorage(应在每次添加之前清除)。 将集合“activeSessions”中生成的id替换为当前用户电子邮件中的“activeID”

    function addToActiveSession() {
      var sesID = gen();
    
      var db = firebase.firestore();
      localStorage.setItem('userID', sesID);
      db.collection("activeSessions").doc(firebase.auth().currentUser.email).set({
        activeID: sesID
      }).catch(function (error) {
          console.error("Error writing document: ", error);
        });
    
    }
    function gen() {
      var buf = new Uint8Array(1);
      window.crypto.getRandomValues(buf);
      return buf[0];
    }
    function signin(){
     firebase.auth().signInWithEmailAndPassword(email, password).then(function (user) {
          
          localStorage.clear();
          addToActiveSession();
          }
        }), function (error) {
          // Handle Errors here.
          var errorCode = error.code;
          var errorMessage = error.message;
          if (errorCode === 'auth/wrong-password') {
            alert('wrong pass');
          } else {
            alert(errorMessage);
          }
          console.log(error);
        };
    }
    
    然后我在每个页面上检查本地存储中的id会话是否与firestore中的“activeID”相同,如果不相同,则注销

    function checkSession(){
      
      var db = firebase.firestore();
      var docRef = db.collection("activeSessions").doc(firebase.auth().currentUser.email);
            docRef.get().then(function (doc) {
              alert(doc.data().activeID);
              alert(localStorage.getItem('userID'));
              if (doc.data().activeID != localStorage.getItem('userID')) {
                alert("bie bie");
                firebase.auth().signOut().then(() => {
            
                  window.location.href = "signin.html";
             }).catch((error) => {
               // An error happened.
             });
                window.location.href = "accountone.html";
              } else{alert("vse ok");}
            }).catch(function (error) {
              console.log("Error getting document:", error);
            });
    }
    
    PS:必须刷新窗口才能注销非活动会话。

    我所做的是:

    在firestore中创建了名为“activeSessions”的集合。用户电子邮件作为对象的id,而“activeID”字段用于保存最近的会话id

    在登录页面代码中:

    每次用户登录时生成用户会话的id。 将此id添加到localstorage(应在每次添加之前清除)。 将集合“activeSessions”中生成的id替换为当前用户电子邮件中的“activeID”

    function addToActiveSession() {
      var sesID = gen();
    
      var db = firebase.firestore();
      localStorage.setItem('userID', sesID);
      db.collection("activeSessions").doc(firebase.auth().currentUser.email).set({
        activeID: sesID
      }).catch(function (error) {
          console.error("Error writing document: ", error);
        });
    
    }
    function gen() {
      var buf = new Uint8Array(1);
      window.crypto.getRandomValues(buf);
      return buf[0];
    }
    function signin(){
     firebase.auth().signInWithEmailAndPassword(email, password).then(function (user) {
          
          localStorage.clear();
          addToActiveSession();
          }
        }), function (error) {
          // Handle Errors here.
          var errorCode = error.code;
          var errorMessage = error.message;
          if (errorCode === 'auth/wrong-password') {
            alert('wrong pass');
          } else {
            alert(errorMessage);
          }
          console.log(error);
        };
    }
    
    然后我在每个页面上检查本地存储中的id会话是否与firestore中的“activeID”相同,如果不相同,则注销

    function checkSession(){
      
      var db = firebase.firestore();
      var docRef = db.collection("activeSessions").doc(firebase.auth().currentUser.email);
            docRef.get().then(function (doc) {
              alert(doc.data().activeID);
              alert(localStorage.getItem('userID'));
              if (doc.data().activeID != localStorage.getItem('userID')) {
                alert("bie bie");
                firebase.auth().signOut().then(() => {
            
                  window.location.href = "signin.html";
             }).catch((error) => {
               // An error happened.
             });
                window.location.href = "accountone.html";
              } else{alert("vse ok");}
            }).catch(function (error) {
              console.log("Error getting document:", error);
            });
    }
    

    PS:必须刷新窗口才能注销非活动会话。

    您需要自己为移动应用程序创建一个令牌。在Firebase数据库的用户节点中创建一个令牌,并在每次登录应用程序时重新生成该令牌,将该令牌与
    AppDiBecomeActive
    appDidFinishLaunching上已登录的用户令牌相匹配方法如果令牌不同,则手动注销用户并将用户带到身份验证屏幕。这里只是一个想法,但这将是一个良好的用户体验吗?我使用iOS设备,以便可以无缝地从一个设备移动到另一个设备-在iMac上聊天,并在移动中抓起手机继续对话(切换).@Jay我认为所有会话的注销用户都有助于提高安全性。@Jay这取决于应用程序类别。如果这是与银行、钱包或个人数据应用程序等安全性相关的内容,则最好保持单用户登录。@Tager我完全同意,这就是我提出问题的原因。如何处理用户与用例直接相关关于应用程序。我认为问题中的更多信息可能会给出答案,但就其本身而言,“注销”的含义有点模糊。换句话说,Firebase可以在节点上有一个观察员,通知应用程序将用户注销Firebase,但这是否也意味着将用户注销应用程序本身?或者他们是否仍然可以访问data他们当时正在检查,没有新数据。您需要自己为移动应用程序检查。在Firebase数据库的用户节点中获取一个令牌,并在每次登录应用程序时重新生成,将此令牌与
    appDidBecomeActive
    appDidFinishLaunching
    方法上已登录的用户令牌匹配,如果令牌是不同的手动注销用户并将用户带到身份验证屏幕。这里只是一个想法,但这将是一个良好的用户体验吗?我使用iOS设备,以便可以无缝地从一个设备移动到另一个设备-在iMac上聊天,并在移动中抓起我的手机继续通话