Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.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/1/firebase/6.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
Node.js 当前环境不支持指定的持久性类型firebase_Node.js_Firebase_Firebase Authentication - Fatal编程技术网

Node.js 当前环境不支持指定的持久性类型firebase

Node.js 当前环境不支持指定的持久性类型firebase,node.js,firebase,firebase-authentication,Node.js,Firebase,Firebase Authentication,我得到这个错误。“当前环境不支持指定的持久性类型。”我在测试我的应用程序时发现,当用户登录时,它会到处登录。因此,我尝试使用firebase在node.js express上实现会话,希望这能解决这个问题。我的代码是: router.post("/login", function (req, res) { email = req.body.email; password = req.body.password; firebase.auth().setPersistence(firebase.a

我得到这个错误。“当前环境不支持指定的持久性类型。”我在测试我的应用程序时发现,当用户登录时,它会到处登录。因此,我尝试使用firebase在node.js express上实现会话,希望这能解决这个问题。我的代码是:

router.post("/login", function (req, res) {
email = req.body.email;
password = req.body.password;

firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION);
firebase.auth().signInWithEmailAndPassword(email, password).then(function () {
    var user = firebase.auth().currentUser;
    firebase.auth().onAuthStateChanged(function (user) {
        if (user) {

            res.redirect("/home");
        }
    });
});});

node.js环境中只支持
none
持久性(这是默认设置)。原因是,当在服务器环境中使用Firebase Auth client library时,可能会有多个用户登录,而您没有在后端服务器上保留currentUser的概念(这会导致一个用户与另一个用户发生冲突)。只能在客户端上修改会话持久性。

谢谢您的回答。那么我应该使用什么来单独验证用户呢?API经过优化,可以在客户端验证用户。在这种情况下,您总是将ID令牌发送到服务器,并在提供受限资源之前使用AdminSDK进行验证。您也可以将其发送到后端,但最终会有多个用户通过该流程。在这种情况下,您需要管理会话。用户会话不会每小时刷新一次。