Firebase 踢出当前用户 [英] Firebase kicks out current user

查看:15
本文介绍了Firebase 踢出当前用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我遇到了这个问题,每次添加新用户帐户时,它都会踢出已经登录的当前用户.我阅读了 firebase api,它说如果创建了新帐户,用户自动登录"但他们从未说过要避免这种情况.

So I have this issue where every time I add a new user account, it kicks out the current user that is already signed in. I read the firebase api and it said that "If the new account was created, the user is signed in automatically" But they never said anything else about avoiding that.

      //ADD EMPLOYEES
      addEmployees: function(formData){
        firebase.auth().createUserWithEmailAndPassword(formData.email, formData.password).then(function(data){
          console.log(data);
        });
      },

我是管理员,正在向我的网站添加帐户.如果我可以在不注销并登录新帐户的情况下添加帐户,我希望它.有什么办法可以避免这种情况?

I'm the admin and I'm adding accounts into my site. I would like it if I can add an account without being signed out and signed into the new account. Any way i can avoid this?

推荐答案

更新 20161110 - 下面的原始答案

另外,查看这个答案以了解不同的方法.

Also, check out this answer for a different approach.

原答案

这实际上是可能的.

但不是直接的,这样做的方法是创建第二个身份验证引用并使用它来创建用户:

But not directly, the way to do it is to create a second auth reference and use that to create users:

var config = {apiKey: "apiKey",
    authDomain: "projectId.firebaseapp.com",
    databaseURL: "https://databaseName.firebaseio.com"};
var secondaryApp = firebase.initializeApp(config, "Secondary");

secondaryApp.auth().createUserWithEmailAndPassword(em, pwd).then(function(firebaseUser) {
    console.log("User " + firebaseUser.uid + " created successfully!");
    //I don't know if the next statement is necessary 
    secondaryApp.auth().signOut();
});

如果您没有指定用于操作的 Firebase 连接,它将默认使用第一个连接.

If you don't specify which firebase connection you use for an operation it will use the first one by default.

来源.

编辑

对于新用户的实际创建,除了管理员之外没有任何人或其他人都没有关系,在第二个身份验证引用上进行身份验证,因为创建帐户所需的只是身份验证引用本身.

For the actual creation of a new user, it doesn't matter that there is nobody or someone else than the admin, authenticated on the second auth reference because for creating an account all you need is the auth reference itself.

以下内容尚未经过测试,但值得考虑

您必须考虑的是将数据写入 Firebase.通常的做法是用户可以编辑/更新他们自己的用户信息,因此当您使用第二个身份验证参考来编写时,这应该可以工作.但是,如果您拥有该用户的角色或权限之类的内容,请确保使用具有正确权限的 auth 引用编写这些内容.在这种情况下,主身份验证是管理员,第二身份验证是新创建的用户.

The thing you do have to think about is writing data to firebase. Common practice is that users can edit/update their own user info so when you use the second auth reference for writing this should work. But if you have something like roles or permissions for that user make sure you write that with the auth reference that has the right permissions. In this case, the main auth is the admin and the second auth is the newly created user.

这篇关于Firebase 踢出当前用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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