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

Advertisements 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… 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?

Advertisements 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?

Advertisements 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(),… Read More How to modify a users firebase authentication token claims?

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

Advertisements 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… Read More Best way to edit package.json file for Firebase Cloud Functions?

Firebase admin sdk calling the wrong catch

Advertisements 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})… Read More Firebase admin sdk calling the wrong catch