Firebase“手动"创建用户

我使用的是标准的电子邮件 + 密码身份验证提供商.

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

在某些情况下,我必须手动创建一个 firebase 用户.该流程类似于使用定义的电子邮件 + 生成的密码调用 REST api,如果成功,则使用他的密码向用户发送欢迎电子邮件.类似于正向用户注册.

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.

我通读了他们的文档,但找不到太多内容.(新的文档甚至不提供用于用户管理的 REST API 部分……好吧,只是要清楚,新的谷歌"风格的文档,无论如何都非常糟糕:)).

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?

顺便说一句:也可以通过 createUserWithEmailAndPassword() 在客户端创建它们,但是这个函数会自动重新验证新用户,这在我的场景中一定不会发生.是否可以在不自动登录用户的情况下使用 createUserWithEmailAndPassword()?

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?

推荐答案

您可以在客户端中创建一个新的 Firebase 应用上下文,然后在那里调用 createUserWithEmailAndPassword():

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');

通过向 initializeApp 添加第二个参数,您可以创建一个单独的上下文,该上下文不会在用户创建时触发重新身份验证.

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

相关文章