当前环境不支持指定的持久性类型Firebase [英] The current environment does not support the specified persistence type firebase

查看:63
本文介绍了当前环境不支持指定的持久性类型Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误. 当前环境不支持指定的持久性类型."我在测试我的应用程序时,发现当用户登录时,它已随处登录.所以我正在尝试使用firebase在node.js express上实现会话,希望这能解决它.我的代码是这样的:

I get this error. "The current environment does not support the specified persistence type." I was testing my app and saw that when a user is logged in it's logged in everywhere. So I'm trying to implement sessions on node.js express using firebase hoping this will solve it. My code is this:

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客户端库时,您可能有多个用户登录,并且没有在后端服务器上持久保存currentUser的概念(这将导致一个用户另一个).会话持久性只能在客户端上修改.

Only none persistence is supported in a node.js environment (it is the default setting). The reason for this is because when Firebase Auth client library is used in a server environment, you could have multiple users logging in and you don't have the notion of a currentUser that is persisted on the backend server (this would cause one user to clobber the other). Session persistence can be modified on the client only.

这篇关于当前环境不支持指定的持久性类型Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆