firebase-admin

Cloud Functions for Firebase database onWrite triggered twice

空扰寡人 提交于 2019-12-05 16:34:01
Hi I am developing a notification system, but I am having trouble deleting the processed notification data. The onWrite event listener is triggered twice resulting to two notifications. Can you help me find a work around so that onWrite event listener should not be triggered twice? It is important to delete the processed data. exports.sendMessageNotification = functions.database.ref('/notification/message/{recipientUid}/{senderUid}').onWrite(event => { /* processing notification and sends FCM */ return admin.messaging().sendToDevice(tokens, payload).then(response => { // For each message check

Disable many users at once

十年热恋 提交于 2019-12-05 16:33:41
We are using Firebase Authentication in a multitenant setup. Under certain circumstances, we want to disable all users for one tenant (trial ended, subscription not renewed ...) or enable all previously disabled users. We send an UpdateRequest for every user that has to be enabled/disabled. Although we send the requests sequentially (only one at a time per tenant and not many tenants are disabled at the same time), we have encountered a quota exceeded error several times: { "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "QUOTA_EXCEEDED : Exceeded quota for

Firebase Admin SDK - Current Logged In User - Nodejs

醉酒当歌 提交于 2019-12-05 05:36:40
问题 How do i get currentUser in firebase admin SDK. In client SDK we can use onAuthStateChanged() or firebase.auth().currentUser() In NodeJs Server.js file firebase admin SDK onAuthStateChanged() Do not work, what should work here? Basically i want only logged in users to access my innerPages so i am using express,nodejs app.get method to create routes. app.get('/', authenticationRequired ,function(req,res){ res.sendFile(path.join(__dirname+'/index.html')); }); And trying to write

TypeError: rtdb.initStandalone is not a function

本小妞迷上赌 提交于 2019-12-05 03:17:48
问题 I'm pretty new to both Node and Firebase, but can't seem to find this error online. I get the following error when I try to load Firebase Database through Firebase Admin: TypeError: rtdb.initStandalone is not a function DatabaseService../node_modules/firebase-admin/lib/database/database.js.DatabaseService.getDatabase node_modules/firebase-admin/lib/database/database.js:62 var db = this.INTERNAL.databases[dbUrl]; if (typeof db === 'undefined') { var rtdb = require('@firebase/database'); db =

nodejs firebase error RangeError: Maximum call stack size exceeded failure

荒凉一梦 提交于 2019-12-05 00:10:50
I have an error from the firebase : FIREBASE WARNING: Exception was thrown by user callback. RangeError: Maximum call stack size exceeded I didn't find my mistake. I'm very lost in here, please help. My code looks like this: app.post('/updateCoords', (req, res)=>{ var usrID = req.body.id; var usrCoords = { lat: req.body.lat, long: req.body.long } console.log('userID : '+usrID+' lat : '+usrCoords.lat+' long : '+usrCoords.long); var ref = database.ref('users'); try{ ref.orderByChild('username').equalTo(usrID).on("value", (snapshot)=> { if(!snapshot.val()){ // Error return res.json({msg:

Firebase Storage upload php

六月ゝ 毕业季﹏ 提交于 2019-12-04 20:48:24
I'm currently trying to upload to the Firebase Cloud Storage using php, but running into an issue. I have a form in html, that takes the uploaded file (in my case an image), and passes it to a php file. This image is very small, 12.8kB, and a JPEG image. The php file takes the image, and tries to upload it to the storage. My current php code is roughly: $storage = new StorageClient(['projectId' => '<my_project_id> ']); $bucket = $storage->bucket('images'); $bucket->upload($_FILES['imageToUpload']['tmp_name']); I can get it to print the bucket name, and it's details, so I know it's not that

Firebase-admin won't write to database, gives no errors

落花浮王杯 提交于 2019-12-04 16:57:06
Firebase admin isn't writing to the database. I am instantiating the database: var db = admin.database(); Then setting up a reference to the table I want: var systemsRef = db.ref("systems/"); I then have a function to check if the 'system', (an encrypted hardware id), exists. function isSystemRegistered(id){ var isTrue; systemsRef.once('value', function(snapshot) { isTrue = (snapshot.hasChild(id))? true : false; }); return isTrue; } Which, as of yet returns false ; which is true , because it doesn't exist yet. If the system doesn't exist, it writes the data. const sysID = getSysID(); var sys

Google Firebase: Get, update or create documents using Python

混江龙づ霸主 提交于 2019-12-04 15:31:41
I am not able to get, update or create the documents in Google Firebase (Cloud Firestore) database using Python. What I have: A) The database with a collection and documents (inserted manually on the web): B) Credential JSON file saved as test.json (it is called often path/to/serviceKey.json in the documentation), which looks like this (redacted): { "type": "service_account", "project_id": "test-6f02d", "private_key_id": "fffca ... 5b7", "private_key": "-----BEGIN PRIVATE KEY-----\n ... 1IHE=\n-----END PRIVATE KEY-----\n", "client_email": "test-admin@test-6f02d.iam.gserviceaccount.com",

Cloud Functions: How to copy Firestore Collection to a new document?

左心房为你撑大大i 提交于 2019-12-04 06:27:12
I'd like to make a copy of a collection in Firestore upon an event using Cloud Functions I already have this code that iterates over the collection and copies each document const firestore = admin.firestore() firestore.collection("products").get().then(query => { query.forEach (function(doc){ var promise = firestore.collection(uid).doc(doc.data().barcode).set(doc.data()); }); }); is there a shorter version? to just copy the whole collection at once? Currently, no. Looping through each document using Cloud Functions and then setting a new document to a different collection with the specified

Firebase in Spring boot gives error during initalization

自古美人都是妖i 提交于 2019-12-04 05:24:54
问题 I'm trying to set up Firebase in Spring Boot app. I'm following the code snippets given in the documentation here. This is how my pom looks: <dependency> <groupId>com.google.firebase</groupId> <artifactId>firebase-admin</artifactId> <version>5.2.0</version> </dependency> The code that I run to initialise firebase: @PostConstruct public void init() { InputStream serviceAccount = FirebaseConfig.class.getClassLoader().getResourceAsStream(configPath); FirebaseOptions options = null; try { options