google-cloud-functions

How to distinguish between the reasons Firebase Transactions return null?

僤鯓⒐⒋嵵緔 提交于 2021-02-18 15:01:13
问题 From my understanding of Transactions, it can return null for two reasons: There is actually no value at the node where the transaction is being performed. The local cache is empty as Firebase Cloud Functions is stateless. Therefore, it may return null the very first time and it will re-run the function. My question is, how do we distinguish between these two cases? Or does firebase do the distinction by itself? Myref.transaction(function(currentData) { if(currentData != null) { return

Can a Cloud Function read from Cloud Storage?

夙愿已清 提交于 2021-02-18 10:14:31
问题 The only docs I can find about using GCF+GCS is https://cloud.google.com/functions/docs/tutorials/storage. AFAICT this is just showing how to use GCS events to trigger GCF. In the docs for GCF dependencies, it only mentions node modules. Is it possible for GCF code to read from a GCS bucket? Is it simply the case of requiring a node module that knows how to communicate with GCS and if so, are there any examples of that? 回答1: Yes, but note that it will store the result in a ramdisk, so you'll

Passing sensitive information to cloud functions

谁都会走 提交于 2021-02-18 09:49:58
问题 Is there an "official" solution for passing sensitive information, such as API keys, to Google Cloud Functions? In particular it would be nice to avoid passing this information as arguments to the function since it will be the same for every invocation. AWS Lambda has a built-in solution using encrypted environment variables for this. Is there some similar approach for Google Cloud Functions? I could imagine using a cloud storage bucket or cloud datastore for this, but that feels very manual.

How can I access a specific folder inside firebase storage from a cloud function?

怎甘沉沦 提交于 2021-02-18 08:40:08
问题 I am using firebase cloud function storage for the first time. I succeeded to perform changes on the default folder by using : exports.onFileUpload = functions.storage.bucket().object().onFinalize(data => { const bucket = data.bucket; const filePath = data.name; const destBucket = admin.storage().bucket(bucket); const file = destBucket.file(filePath); but now I want the function to be triggered from a folder inside the storage folder like this How can I do that? 回答1: There is currently no way

Could not find a declaration file for module 'firebase-tools'

女生的网名这么多〃 提交于 2021-02-18 03:19:41
问题 I am writing my first cloud function for Firebase and it requires the firebase-tools module. I've installing it by adding it to my dependencies in the package.json file and running npm install . Then I tried to import it using import * as tools from 'firebase-tools'; , but I get this error: Could not find a declaration file for module 'firebase-tools'. 'c:/Users/LENOVO/Nouveau dossier/functions/node_modules/firebase-tools/lib/index.js' implicitly has an 'any' type. Try npm install @types

Could not find a declaration file for module 'firebase-tools'

大憨熊 提交于 2021-02-18 03:18:27
问题 I am writing my first cloud function for Firebase and it requires the firebase-tools module. I've installing it by adding it to my dependencies in the package.json file and running npm install . Then I tried to import it using import * as tools from 'firebase-tools'; , but I get this error: Could not find a declaration file for module 'firebase-tools'. 'c:/Users/LENOVO/Nouveau dossier/functions/node_modules/firebase-tools/lib/index.js' implicitly has an 'any' type. Try npm install @types

Could not find a declaration file for module 'firebase-tools'

随声附和 提交于 2021-02-18 03:17:52
问题 I am writing my first cloud function for Firebase and it requires the firebase-tools module. I've installing it by adding it to my dependencies in the package.json file and running npm install . Then I tried to import it using import * as tools from 'firebase-tools'; , but I get this error: Could not find a declaration file for module 'firebase-tools'. 'c:/Users/LENOVO/Nouveau dossier/functions/node_modules/firebase-tools/lib/index.js' implicitly has an 'any' type. Try npm install @types

Firestore transactions getting triggered multiple times resulting in wrong data

南楼画角 提交于 2021-02-17 20:55:15
问题 So I have a cloud function that is triggered each time a transaction is liked/unliked. This function increments/decrements the likesCount . I've used firestore transactions to achieve the same. I think the problem is the Code inside the Transaction block is getting executed multiple times, which may be correct as per the documentation. But my Likes count are being updated incorrectly at certain times. return firestore.runTransaction(function (transaction) { return transaction.get(transRef)

Add additional data to user profile via firestore functions onCreate

删除回忆录丶 提交于 2021-02-17 07:01:12
问题 I'm trying to automatically create a user data in my firestore db when user sign up through firestore functions. However I got 2 option for sign up. Bussiness account and personal account. If user signup as bussiness then I want to add "usertype = 1" into my document and when personal then "usertype=2" I managed to automaticaly create a document on signup via functions const functions = require('firebase-functions') const admin = require('firebase-admin') admin.initializeApp() const db =

Limit Firebase Cloud Function To IP Addresses

五迷三道 提交于 2021-02-17 06:17:04
问题 I have several Cloud Functions that are all setup and working well, each of type https.onRequest(... . I am trying to figure out the best / easiest way to allow the https.onRequest functions to be called only by specified IP addresses. Can this be accomplished? I am guessing I need to create a service account with conditions, but I haven't been able to achieve the results I want. 回答1: You could use a GCE VM as proxy with a firewall rule to only accept incoming traffic form the IP that you