我的Firebase网站只允许一个用户随时登录,为什么? [英] My Firebase website only allows one user logged in at all times, why?

查看:258
本文介绍了我的Firebase网站只允许一个用户随时登录,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从一台设备上登录并在任何其他设备上打开网站(我的电话,我的朋友的笔记本电脑,我的邻居的电脑),网站显示我登录所有这些设备。

如果我注销,我显示为已注销所有设备。



实际上,我的网站一次只能被一个用户使用,这是绝对没有意义的。



滥用Firebase身份验证。


$ b

CODE:


$ b $

  router.post('/ login',function(req,res,next){
var email = req.body.email;
var password = req.body.password;
$ b //验证
req.checkBody('email','Email is required')。notEmpty();
req.checkBody('电子邮件,电子邮件无效)isEmail();
req.checkBody('password','Password is required')。notEmpty();

var errors = req .validationEr rors();

if(errors){
res.render('users / login',{
errors:errors
});
} else {

firebase.auth()。signInWithEmailAndPassword(email,password).then(authData => {

console.log(Authenticated user );
req.flash('success_msg','您已经登录');
res.redirect(/ fun / index);


var errorCode = error.code;
var errorMessage = error.message;
console.log(Login Failed: ,错误);
req.flash('error_msg',未知用户或密码);
res.redirect('/ users / login');

} );
}
});






问题:



我犯了什么错误,我该如何解决它?




编辑:发现这个: Firebase NodeJS身份验证



但问题依然没有答案。 解决方案

如果您使用<一个href =https://firebase.google.com/docs/auth/admin/ =nofollow noreferrer> node.js管理软件开发工具包,您实际上处于单用户状态,服务器是单个用户。通常情况下,该单个用户是一个特权服务帐户,但似乎您正在使用它来同时登录各个用户。这不是支持管理SDK的用例。

如果您希望每个用户登录您的网站,您必须在浏览器中使用网络版SDK 。 Web SDK代表已登录的用户安全地与Firebase服务直接通信。


SITUATION:

If I log in from one device and open the website on any other device (my phone, my friend's laptop, my neighbour's pc), the website shows me as logged in on all those devices.

If I log out, I am shown as logged out on all devices.

Effectively, my website can only be used by one user at a time which is absolutely pointless.

I must somehow have misused Firebase authentication.


CODE:

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

    // Validation
    req.checkBody('email', 'Email is required').notEmpty();
    req.checkBody('email', 'Email is not valid').isEmail();
    req.checkBody('password', 'Password is required').notEmpty();

    var errors = req.validationErrors();

    if(errors){
        res.render('users/login', {
            errors: errors
        });
    } else {

        firebase.auth().signInWithEmailAndPassword(email, password).then(authData => { 

            console.log("Authenticated user with uid:",authData);
            req.flash('success_msg', 'You have logged in');
            res.redirect("/fun/index");

        }).catch(error => { 

            var errorCode = error.code;
            var errorMessage = error.message;
            console.log("Login Failed: ", error);
            req.flash('error_msg', "Unknown user or password");
            res.redirect('/users/login');

        });
    }
});


QUESTION:

What mistake have I made and how do I fix it ?


EDIT: Found this: Firebase NodeJS Authentication

But the question remained without an answer.

解决方案

If you're using the node.js admin SDK, you are effectively in a single-user situation, and your server is the single user. Typically, that single user is a privileged service account, but it appears you're using it to log in individual users simultaneously. That's not a supported use case for the admin SDK.

If you want per-user login for your web site, you'll have to authenticate in the browser itself using the web SDK. The web SDK communicates directly with Firebase services, securely, on behalf of the user that's signed in.

这篇关于我的Firebase网站只允许一个用户随时登录,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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