调用方法createUserWithEmailAndPassword而不执行登录

时间:2018-08-08 01:35:37

标签: angular firebase firebase-authentication

在我的系统中,我需要从经过身份验证的用户创建用户,但是为此,我需要通过createUserWithEmailAndPassword方法创建用户,并且在通过此方法创建用户时,身份验证状态会更改为是目前创建的。

是否有一种方法可以从经过身份验证的用户创建用户,而无需通过createUserWithEmailAndPassword方法创建的用户进行登录?

我有一个使用Angular + Node.js开发的系统

  createUser(user: Usuario): Promise<firebase.auth.UserCredential> {
    return this._angularFireAuth.auth.createUserWithEmailAndPassword(user.email, user.password);
  }

3 个答案:

答案 0 :(得分:0)

听起来像管理员功能。参见Introduction to the Admin Auth API

  

用户管理

     

在以下位置访问Firebase控制台并不总是很方便   为了管理您的Firebase用户。管理员用户管理API   为这些相同的用户提供程序化访问。它甚至允许你   做Firebase控制台无法做的事情,例如检索用户的   完整数据并更改用户的密码,电子邮件地址或电话   数字。

答案 1 :(得分:0)

[ANSWER]

您可以在客户端中创建新的Firebase App上下文,然后再次调用createUserWithEmailAndPassword()。这将不会重新验证到创建的新用户。 Reference

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

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

执行此操作时可能出现的问题是:Firebase App named '[DEFAULT]' already exists (app/duplicate-app)

[其他场景(供其他参考)]

我想你是说其中之一:

  1. 您希望登录的用户即使在关闭浏览器后仍保持登录状态。在这种情况下,您可以使用firebase auth提供的持久性。

  2. 当用户状态从“未登录”更改为“已登录”时,您想隐藏登录按钮。然后,您可以检查此post

  3. 其他参考:How to keep user logged in with Firebase no matter what?

希望有帮助!

答案 2 :(得分:0)

创建用户后,您需要调用signInWithEmailAndPassword登录。

    signInFirebaseWithEmailAndPassword(
       userName: string,
       password: string
    ): Promise<firebase.auth.UserCredential> {
       return this._angularFireAuth.auth.signInWithEmailAndPassword(userName, password);
    }