【发布时间】:2017-07-21 17:15:52
【问题描述】:
我在 Cloud Function for Firebase 中使用 Node.js Admin SDK,我想调用 admin.auth().getUserByEmail() 方法。
因为我使用的是云函数,所以我阅读了here,我只需要调用admin.initializeApp(functions.config().firebase);,您可以在下面看到我已经完成了。
但是,当我调用 getUserByEmail()(仅在本地测试)时,我收到以下错误:
'No Firebase project was found for the provided credential.'
这是我的 index.js
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.hello = functions.https.onRequest(function (req, resp) {
var from = req.body.sender;
admin.auth().getUserByEmail(from)
.then(function (userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log("Successfully fetched user data:", userRecord.toJSON());
})
.catch(function (error) {
console.log("Error fetching user data:", error);
})
});
有没有人有这方面的经验,可以告诉我我做错了什么?
【问题讨论】:
标签: javascript firebase google-cloud-functions firebase-admin