如何在Firebase 3中创建用户并且不对其进行身份验证?

gcf*_*bri 10 firebase angularfire firebase-authentication

我正在开发一个angularfire项目,我想知道如何在Firebase 3中创建用户,一旦完成,不要对指定用户进行身份验证.在之前的Firebase版本中,我们使用了名为createUser(email,password)的方法.现在我们只有createUserWithEmailAndPassword(电子邮件,密码)方法,它创建并验证指定的用户.

Jay*_*Jay 10

这个问题的答案是:你做不到.

我们有类似的情况,我们有'admin'用户,可以创建其他用户.使用2.x时,这很容易.使用3.x时,由于该功能被完全删除,因此失败.

如果您在3.x中创建用户,则以该用户身份进行身份验证,并取消验证登录的帐户.

这会更深入,因为您需要重新进行身份验证以创建另一个用户; 因此管理员要么手动执行,要么(畏缩)在本地存储身份验证数据,因此它可能是一个自动化过程(畏缩,请不要这样做)

Firebase公开强调2.x将继续得到支持,因此您可能只想避免3.x.

更新:

其中一个Firebaser实际上提出了一个解决方法.从概念上讲,您有一个管理员用户登录.然后,您创建第二个连接到firebase并与另一个用户进行身份验证,然后该连接将创建新用户.冲洗 - 重复.

再次更新

看到这个问题和答案

Firebase推出了当前用户


elb*_*vas 5

您可以使用云功能和 Firebase 管理 SDK 来执行此操作。创建如下所示的 HTTP 函数。

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);

// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions

exports.createUser = functions.https.onRequest((request, response) => {
    if (request.method !== "POST") {
        response.status(405).send("Method Not Allowed");
    } else {
        let body = request.body;

        const email = body.email;
        const password = body.password;
        const displayName = body.displayName;

        admin.auth().createUser({
            email: email,
            emailVerified: false,
            password: password,
            displayName: displayName,
            disabled: false
        })
        .then((userRecord) => {
            return response.status(200).send("Successfully created new user: " +userRecord.uid);
        })
        .catch((error) => {
            return response.status(400).send("Failed to create user: " + error);
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

在您的客户端应用程序中,使用 Http 请求调用此函数,例如使用 ajax

$.ajax({
       url: "the url generated by cloud function",
       type: "POST",
       data: {
           email: email,
           password: password,
           displayName: name
       },
       success: function(response) {
            console.log(response);
       },
       error: function(xhr, status, error) {
             let err = JSON.parse(xhr.responseText);
                 console.log(err.Message);
             }
       });
Run Code Online (Sandbox Code Playgroud)