admin.messaging() is not a function while on "firebase-admin": "^11.3.0",

I’ve been trying to send a notfication to topic "All" and the console log shows error: Notification sent failed: TypeError: admin.messaging is not a function Code: // The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers. const functions = require(‘firebase-functions’); // The Firebase Admin SDK to access Firestore. var admin… Read More admin.messaging() is not a function while on "firebase-admin": "^11.3.0",

How to query Firebase with Node.js and "firebase-admin" SDK?

After initializing Firebase like this: import * as admin from "firebase-admin" const firebaseApp = admin.initializeApp({ credential: admin.credential.cert(keys), }) export const db = firebaseApp.firestore() I want to get all documents of one collection ("players"). I use this: const ref = db.collection(‘players’); const allPlayers = await ref.get(); And I get this object as a result: QuerySnapshot {… Read More How to query Firebase with Node.js and "firebase-admin" SDK?

How to modify a users firebase authentication token claims?

How can I update a users claims if the map returned is an immutable map? This is example code from Firebase Auth docs on how to update claims: UserRecord user = FirebaseAuth.getInstance() .getUserByEmail("user@admin.example.com"); Map<String, Object> currentClaims = user.getCustomClaims(); //This returns an immutable map if (Boolean.TRUE.equals(currentClaims.get("admin"))) { currentClaims.put("level", 10); //This will throw an exception FirebaseAuth.getInstance().setCustomUserClaims(user.getUid(), currentClaims);… Read More How to modify a users firebase authentication token claims?

Best way to edit package.json file for Firebase Cloud Functions?

I get a parsing error when attempting to deploy a cloud function that the firebase-tools module cannot be found. I looked in my package.json file and notice that it’s missing, so I want to add it. I also noticed that the other dependencies have versions specified. Are these version numbers updated automatically when I update… Read More Best way to edit package.json file for Firebase Cloud Functions?

Firebase admin sdk calling the wrong catch

I am trying to add a new user with firebase-admin and then to save a new document in a custom collection. Sample code following: admin.auth().createUser(user) .then((record) => { user.uid = record.uid; userCollection.doc(record.uid).set({…user}) .then(writeResult => { resolve(); }) .catch(reason => { reject(reason) }); }) .catch((err) => { reject(err); }); The problem is, if the userCollection.doc(record.uid).set({…user}) fails,… Read More Firebase admin sdk calling the wrong catch