无法使用适用于 Firebase 的云功能通过电子邮件获取用户



我正在 Firebase 的 Cloud Function 中使用 Node.js Admin SDK,我想调用admin.auth().getUserByEmail()方法。

由于我使用的是云函数,我在这里读到我只需要调用admin.initializeApp(functions.config().firebase);您可以在下面看到我已经完成了。

但是,当我调用getUserByEmail()(仅在本地测试(时,出现以下错误:'No Firebase project was found for the provided credential.'

这是我的索引.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);
})
});

有没有人对此有任何经验,可以告诉我我做错了什么?

如果您使用的是localy(在Google Cloud Functions模拟器中(,则管理员sdk将不会获得正确的配置json。您必须使用从 Firebase 控制台获取的服务帐号 json。

但是,如果您已部署它,则您的方法将正常工作。

最新更新