我已经部署了以下云功能:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.getAllUsers = functions.https.onRequest((req: any, res: any) => {
return admin.listUsers().then((userRecords: any) => {
userRecords.users.forEach((user: any) => console.log(user.toJSON()));
res.end('Retrieved all users successfully.');
}).catch((error: any) => console.log('Request failed: ', error));
})
但是每当我尝试运行它时,都会出现以下错误:
TypeError: admin.listUsers is not a function
at exports.getAllUsers.functions.https.onRequest (/srv/functions/lib/index.js:102:11)
at cloudFunction (/srv/functions/node_modules/firebase-functions/lib/providers/https.js:57:9)
at process.nextTick (/srv/node_modules/@google-cloud/functions-framework/build/src/invoker.js:243:17)
at process._tickCallback (internal/process/next_tick.js:61:11)
我该如何解决?以及如何添加参数以对数据进行分页,即一次获取100个用户?我期望将端点称为:curl http://localhost:5000/sweltering-fire-5301/us-central1/getAllUsers。参数为“ http://localhost:5000/sweltering-fire-5301/us-central1/getAllUsers?limit=5&page=2”
答案 0 :(得分:1)
如果您这样导入管理SDK:
Spring
然后像这样对listUsers可用:
const admin = require("firebase-admin")
您可能想查看documentation和API reference,因为它们具有实现此功能所需的一切。