我正在尝试使用 Firebase 云功能创建到服务器端的登录 GET 请求。
是否可以使用 firebase 函数进行身份验证?我在函数文件夹中尝试了 npm i firebase
,但它无法工作。
是否可以选择使用服务器端代码创建用户?
最佳答案
要从 Cloud Functions 中创建 Firebase 身份验证用户,请使用 Node.js 的 Firebase Admin SDK。
要安装它,请遵循 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); });
关于firebase - 创建用户服务器端 Firebase 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47268411/