Firebase以“手动”方式创建用户 [英] Firebase create user "manually"

查看:139
本文介绍了Firebase以“手动”方式创建用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用标准的Email +密码认证提供程序。

在某些情况下,我必须手动创建一个Firebase用户。这个流程就像使用定义的电子邮件+生成的密码来调用REST api一样,如果成功,用他的密码向用户发送欢迎电子邮件。就像转发用户注册一样。

我通过他们的文档阅读,找不到太多东西。 (新的文档甚至不提供用户管理的REST API部分..好,只是要清楚,新的谷歌风格的文档,非常吸吮:))。

有人已经做了类似的事情,可以帮助我吗?

BTW:也可以通过 createUserWithEmailAndPassword(),但是这个函数会自动重新认证新用户,这在我的场景中是不会发生的。是否可以使用 createUserWithEmailAndPassword()而不自动登录用户?

您可以在您的客户端中创建一个新的Firebase App上下文,然后在该处调用 createUserWithEmailAndPassword()

  var authApp = firebase.initializeApp({
// ...
},'authApp');
var detachedAuth = authApp.auth();

detachedAuth.createUserWithEmailAndPassword('foo@example.com','asuperrandompassword');

通过向 initializeApp 添加第二个参数创建一个单独的上下文,当用户创建时,不会触发重新验证。


I'm using the standard Email + Password auth-provider.

Through certain circumstances I have to create a firebase user manually. The flow would be something like calling a REST api with an defined email + generated password, and if succeeded sending a welcome email to the user with his password. Something like forward user registration.

I read through their docs and couldn't find much. (the new docs don't even offer a REST API section for user management.. well and just to be clear, the new "google" styled docs, pretty much suck anyway :) ).

Is there someone who has already done something similar and can help me out?

BTW: It would also be possible to create them client side through createUserWithEmailAndPassword(), but this function does automatically reauthenticate the new user, which must not happen in my scenario. Is it possible to use createUserWithEmailAndPassword() without automatically logging in the user?

解决方案

You can create a new Firebase App context in your client and then call createUserWithEmailAndPassword() there:

var authApp = firebase.initializeApp({
  // ...
}, 'authApp');
var detachedAuth = authApp.auth();

detachedAuth.createUserWithEmailAndPassword('foo@example.com', 'asuperrandompassword');

By adding a second argument to initializeApp you create a separate context that will not trigger re-authentication upon user creation.

这篇关于Firebase以“手动”方式创建用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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