创建用户服务器端Firebase功能

时间:2017-11-13 15:56:21

标签: firebase firebase-authentication

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

是否可以使用firebase功能进行身份验证?我在函数文件夹中尝试了View view = getView(); view.post() ,但它无法正常工作。

是否有使用服务器端代码创建用户的选项?

1 个答案:

答案 0 :(得分:4)

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

要安装它,请按照instructions in the documentation进行操作。主要是:

$ npm install firebase-admin --save

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

var admin = require("firebase-admin");

要创建用户,请按照instructions in this documentation

进行操作
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);
  });
相关问题