logo
Tags down

shadow

CloudFunctions.getHttpsCallable parameters


By : ivanlivov
Date : October 18 2020, 06:10 AM
To fix the issue you can do Although I can't explain why it was designed this way, some people might find this post looking for help using the getHttpsCallable function. Here is an example calling a cloud function called addUser with two parameters, email and password. These parameters would normally be defined in another way such as via the text property of a TextController.
code :
CloudFunctions.instance.getHttpsCallable(
                          functionName: "addUser",
                      ).call(
                          <String, dynamic>{
                            "email": "test@test.com",
                            "password": "Terrific password!"
                          },
                      );


Share : facebook icon twitter icon

Error submitting Cloudbuild job from Cloudfunctions if


By : Madiha Noreen
Date : March 29 2020, 07:55 AM
To fix the issue you can do The Cloud KMS API was not enabled on the project running Cloudbuild. It's unfortunate that the error message was so vague. In fact, I diagnosed the issue by running gcloud kms decrypt ... in a Cloudbuild job which helpfully told me that the API needed to be enabled.

how to retrieve data with the getHttpsCallable method


By : Pruthvi Raj
Date : March 29 2020, 07:55 AM
should help you out You can await the call method of httpsCallable.
The example app has the usage:
code :
                try {
                  final HttpsCallableResult result = await callable.call(
                    <String, dynamic>{
                      'message': 'hello world!',
                      'count': _responseCount,
                    },
                  );
                  print(result.data);
                  setState(() {
                    _response = result.data['repeat_message'];
                    _responseCount = result.data['repeat_count'];
                  });
                } on CloudFunctionsException catch (e) {
                  print('caught firebase functions exception');
                  print(e.code);
                  print(e.message);
                  print(e.details);
                } catch (e) {
                  print('caught generic exception');
                  print(e);
                }

CloudFunctions: Request is sending twice


By : Michael
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , It is not very clear from your code why it would send the notification twice (since you check that userTo.data().userId !== sentBy). But what is sure is that you are not returning a Promise that resolves when all the asynchronous operations (get() and sendToDevice()) are completed.
I would suggest you watch the official Video Series (https://firebase.google.com/docs/functions/video-series/) which explain very well this point about returning Promises for background functions (in particular the ones titled "Learn JavaScript Promises").
code :
exports.sendRequestNotification = functions.firestore
    .document('users/{userId}/requests/{requestId}')
    .onCreate((snap, context) => {

        const db = admin.firestore();

        const docReq = snap.data();
        /*console.log(docReq)*/

        const sentBy = docReq.sentBy;
        const sentTo = docReq.sentTo;

        // Get push token user to (receive)
        return db.collection('users')
            .where('userId', '==', sentTo)
            .get()
            .then(querySnapshot => {

                //We know there is only one document (i.e. one user with this Id), so lets use the docs property
                //See https://firebase.google.com/docs/reference/js/firebase.firestore.QuerySnapshot.html#docs

                const userTo = querySnapshot.docs[0];

                if (userTo.data().pushToken && userTo.data().userId !== sentBy) {
                    // Get info user from (sent)
                    return db.collection('users')
                        .where('userId', '==', sentBy)
                        .get();

                } else {
                    console.log('User request or token not found')
                    throw new Error('User request or token not found');

                }

            })
            .then(querySnapshot => {

                const userFrom = querySnapshot.docs[0];

                const payload = {
                    notification: {
                        title: `${userFrom.data().nickname}`,
                        body: `requestNotify`,
                        badge: '1',
                        sound: 'default'
                    }
                }

                return admin
                    .messaging()
                    .sendToDevice(userTo.data().pushToken, payload);
            })
            .catch(error => {
                console.log('Error:', error);
                return false;
            })

    })

Update Sub-collections on CloudFunctions


By : user3351618
Date : March 29 2020, 07:55 AM
hop of those help? I finally figured out how to do this with nesting promises. Here is the solution:
code :
exports.updateFavoritedProducts = functions.firestore.document('products/{productId}').onUpdate((change, context) => {
    const data = change.after.data();
    const productID = data.id;

 return db.collection('products').where('id', '==', productID).get().then((productsQuerySnap) => {

    productsQuerySnap.forEach((productQuerySnap) => {
        const newPrice = productQuerySnap.data().price;
        const newPriceUnit = productQuerySnap.data().priceUnit;

        db.collection('users').get().then((usersQuerySnap) => {
            usersQuerySnap.forEach((userQuerySnap) => {

                return db.collection('users').doc(userQuerySnap.id).collection('favorites').doc(productQuerySnap.id).update({ 
                    price: newPrice,
                    priceUnit : newPriceUnit

                 }).catch((err) => {
                    console.log('Error getting documents', err);
                    return Promise.reject(err);
                    });
                });
                return null
            })
            .catch((err) => {
                console.log('Error getting documents', err);
                return Promise.reject(err);
            });
        return null
    });
    return null
})
    .catch((err) => {
        console.log('Error getting documents', err);
        return Promise.reject(err);
    });
});

Change nested sub-collections on CloudFunctions


By : Nikita
Date : October 03 2020, 06:00 PM
seems to work fine It depends what do you exactly want to query.
If you want to query only ONE specific product document within the products sub-collection of ONE given store document you would do as follows:
code :
var docRef = db.collection("stores").doc(storeId).collection("products").doc(productId)

docRef.get().then(function(doc) {
    if (doc.exists) {
        console.log("Document data:", doc.data());
    } else {
        // doc.data() will be undefined in this case
        console.log("No such document!");
    }
}).catch(function(error) {
    console.log("Error getting document:", error);
});
db.collection("stores").doc(storeId).collection("products").get()
  .then(function(querySnapshot) {
     //....
  })
  .catch(function(error) {
     //....
  });
var productsCollGroup = db.collectionGroup('products');

productsCollGroup.get()
.then(function (querySnapshot) {
     //....
})
.catch(function(error) {
     //....
});
Related Posts Related Posts :
  • Issue with connecting Golang application on Cloud Run with Firestore
  • Is it possible to export cpu and memory usage from firebase test lab results?
  • BigQuery: How can I append results to an existing table?
  • Firestore social network data structure
  • Flutter FirebaseDatabase run transaction crash
  • How to read a firestore value in a map?
  • Why is my snapshot showing it contains data?
  • Why does firebase performance use the window object?
  • How to setup test data when testing Firestore Rules with Emulator?
  • Firebase authentication facebook provider usage with signInAndRetrieveDataWithCredential()
  • " Cloud Firestore Override a deprecated API " Error occurs when build the flutter application
  • Working with Azure notification hub using IONIC 3
  • What exactly is "source" in the context of Firebase rewrites?
  • Preserving line breaks in TextField with Firebase
  • How to import Firebase only on client in Sapper?
  • concerns about required A records for setting up Firebase Dynamic Links with a custom subdomain
  • How do I Check if an email address is real or fake in flutter
  • Scheduled Cloud Functions Firebase
  • Firebase Functions onUpdate circular problem
  • 2 different Firestore interfaces
  • How do I integrate Flutter web with Firebase?
  • React Native build failed - "Error: While trying to resolve module `react-native-firebase`"
  • Firestore - unexpected reads
  • Is a Firestore document locked when read by the server (cloud-function) in a Transaction?
  • Installing the localized version of firebaseui in a react project
  • Firebase Dynamic Link on Flutter
  • How do I fix Firestore SDK hitting "An internal error was encountered in the Indexed Database server" error on
  • How to access firebase-functions environment configuration from Cloud Run
  • Running Firebase Emulator on GitLab CI
  • Can I get `firebase deploy` to first run `yarn build` before starting the upload?
  • Firestore.settings() requires its first argument to be of type object but it was a custom object
  • firebase functions:shell onWrite property undefined
  • Firebase Firestore reads and pricing
  • Is Firedatabase.SetPersistent (true) minimiza downloading data?
  • Migrating drupal users to firebase auth
  • How to get the download URL from firebase with flutter?
  • Cloud Firestore Security Rules - only allow write to specific key in document
  • How to sort datas from firestore to a map by date in flutter
  • I am not able to move the arrow keys or even select the default project while installing the firebase in mac
  • Collection group queries getting denied by firebase rules
  • Load Tweets live to be displayed on front-end
  • How to get "Apps Instance Id" in Flutter
  • Implementing Firebase Crashlytics in React native application - Android
  • How to pass data from one provider model to another?
  • Authorize a user after they've signed up for my firebase app
  • Delete sent push notification in React Native
  • firebase how to deploy only specific function of express() app
  • HTTP Error: 429, Quota exceeded for quota group 'ReadGroup'
  • How do I implement access control permissions on Firebase Storage?
  • Flutter: How to add multiple Firebase projects to my Flutter project
  • Is there a simple way to cache cloud firestore documents locally in flutter (not offline persistence)?
  • Dependency issue when linking app to Firebase Crashlytics - maven/android/flutter
  • Is it possible for Firebase to alert me based on a certain event parameter?
  • Can we use a Boolean as env variable in Firebase Functions
  • Failed to create Firebase Dynamic Link using react-native-firebase - React Native
  • Firebase Facebook Authentication gives error Refused to display <oauth redirect url> in a frame because it set 'X-
  • How to connect Firebase to a custom domain purchased through Google Domains?
  • Firebase deploy error : Can't allocate regions
  • How to get data from firestore document fields in flutter?
  • Importing Firebase_Messaging makes build fail
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk