所以我有一个问题,每次我添加一个新的用户帐户,它踢出当前用户已经登录。我读过firebase api,上面说“如果创建了新帐户,用户将自动登录”,但他们从来没有说过要避免这种情况。
//ADD EMPLOYEES
addEmployees: function(formData){
firebase.auth().createUserWithEmailAndPassword(formData.email, formData.password).then(function(data){
console.log(data);
});
},
我是管理员,我正在添加帐户到我的网站。我想它,如果我可以添加一个帐户没有被注销,并签署到新的帐户。有什么办法可以避免吗?
14条答案
按热度按时间yws3nbqq1#
我刚刚创建了一个firebase函数,它在创建firestore文档时触发(规则只写入管理员用户)。然后使用admin.auth().createuser()正确创建新用户。
您可以使用functions.https.oncall()
叫它。
kqlmhetl2#
如果您使用的是聚合物和火基(polymerfire),请参阅以下答案:https://stackoverflow.com/a/46698801/1821603
从本质上说,您创建了一个辅助
<firebase-app>
在不影响当前用户的情况下处理新用户注册。webghufk3#
swift版本:
uubf1zoe4#
在web上,这是由于在注册上下文之外调用createuserwithemailandpassword时出现意外行为所致;e、 g.通过创建新用户帐户邀请新用户加入你的应用程序。
似乎,createuserwithemailandpassword方法会触发一个新的刷新令牌,用户cookie也会更新(这种副作用没有记录)
以下是websdk的解决方法:在创建新用户之后;
前提是您事先与原始用户启动loggedinuser。
hm2xizp95#
更新20161110-原始答案如下
另外,请查看此答案以了解不同的方法。
原始答案
这其实是可能的。
但不是直接的,方法是创建第二个auth引用并使用该引用创建用户:
如果您不指定用于操作的firebase连接,则默认情况下,它将使用第一个firebase连接。
多个应用程序引用的源。
编辑
对于新用户的实际创建,除了管理员之外没有人或其他人在第二个auth引用上进行身份验证并不重要,因为创建帐户所需的只是auth引用本身。
以下内容尚未测试,但值得思考
您必须考虑的是将数据写入firebase。通常的做法是,用户可以编辑/更新他们自己的用户信息,所以当您使用第二个auth引用进行编写时,这应该是可行的。但是,如果您对该用户具有类似角色或权限的权限,请确保使用具有正确权限的auth引用来编写。在本例中,主身份验证是admin,第二身份验证是新创建的用户。
vbopmzt16#
以下是对jcabrera答案的快速修改:
nzrxty8p7#
更新20161108-原始答案如下
firebase刚刚发布了firebase管理sdk,它允许服务器端代码用于这个和其他常见的管理用例。阅读安装说明,然后深入阅读有关创建用户的文档。
原始答案
目前这是不可能的。创建一个电子邮件+密码用户会自动将该新用户登录。
s1ag04yj8#
我也面临同样的问题,我用这种方式解决了它:
当用户登录时,我将电子邮件和密码保存在共享首选项中。在创建用户之后,我用之前保存的电子邮件和密码再次登录用户。
vhipe2zx9#
swift 5:简单解决方案
首先将当前用户存储在名为originaluser的变量中
然后,在创建新用户的完成处理程序中,使用updatecurrentuser方法还原原始用户
wnavrhmk10#
我找到安德烈了é'在objective-c中使用firebase ios sdk是一种非常聪明的解决方法:
3zwtqj6y11#
android解决方案(kotlin):
1.您需要firebaseoptions生成器(!)用于设置api键、db url等,不要忘记在最后调用build()
2.通过调用firebaseapp.initializeapp()生成辅助身份验证变量
3.通过传递新创建的二级身份验证来获取firebaseauth示例,并执行任何您想要的操作(例如createuser)
fcipmucu12#
您可以使用firebase函数添加用户。
svmlkihl13#
下面是一个使用websdk的简单解决方案。
创建云函数(https://firebase.google.com/docs/functions)
从应用程序调用此函数
或者,可以使用返回的uid设置用户文档信息。
zqdjd7g914#
swift 4更新
我尝试了几种不同的方法从一个帐户创建多个用户,但这是迄今为止最好、最简单的解决方案。
尼科的原始答案
首先在appdelegate.swift文件中配置firebase
在创建帐户的操作中添加以下代码。