创建用户服务器端Firebase函数

J. *_*Doe 2 firebase firebase-authentication

我正在尝试使用Firebase云功能创建到服务器端的登录GET请求。

是否可以使用Firebase函数进行身份验证?我npm i firebase在functions文件夹内尝试过,但是无法正常工作。

是否可以使用服务器端代码创建用户?

Fra*_*len 5

要在Cloud Functions中创建Firebase身份验证用户,请使用Firebase Admin SDK forNode.js。

要安装它,请按照文档中的说明进行操作。通常是:

$ npm install firebase-admin --save
Run Code Online (Sandbox Code Playgroud)

然后使用以下命令将其导入到index.js中:

var admin = require("firebase-admin");
Run Code Online (Sandbox Code Playgroud)

要创建用户,请遵循本文档中的说明

admin.auth().createUser({
  email: "user@example.com",
  emailVerified: false,
  phoneNumber: "+11234567890",
  password: "secretPassword",
  displayName: "John Doe",
  photoURL: "http://www.example.com/12345678/photo.png",
  disabled: false
})
  .then(function(userRecord) {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log("Successfully created new user:", userRecord.uid);
  })
  .catch(function(error) {
    console.log("Error creating new user:", error);
  });
Run Code Online (Sandbox Code Playgroud)