Ad
TypeError: Admin.listUsers Is Not A Function
I have deployed the following cloud function:
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));
})
But whenever I try to run it, I get the following 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)
How do I resolve it? And how do I add a parameter to paginate my data, i.e. to get 100 users at a time or something? I am expecting to call the endpoint as follows: curl http://localhost:5000/sweltering-fire-5301/us-central1/getAllUsers. How would it look like with a parameter i.e. 'http://localhost:5000/sweltering-fire-5301/us-central1/getAllUsers?limit=5&page=2'
Ad
Answer
If you imported the admin SDK like this:
const admin = require("firebase-admin")
Then listUsers is available to you like this:
admin.auth().listUsers()
You might want to check out the documentation and API reference, as they have everything you need to make this happen.
Ad
source: stackoverflow.com
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?
Ad