1

I'm a designer with little experience with Firebase, so forgive me if I'm not asking the right question. I recently migrated my React Native app from one Firebase account to another, and now data has stopped being pulled in to the app (but data is being received in Firebase).

The app essentially tracks a users habit (inputted from a user), and on the profile displays info from aggregated data that's a Collection from Firebase.

However, a function that should load the aggregated data within a view gives me an error saying that the data can't be found.

Here's the function that should be pulling the data from Firebase (as far as I can tell).

  // States
  const [timeWindowType, setTimeWindowType] = React.useState<TimeWindowTypes>(
    defaultWindowType,
  );
  const [overview, setOverview] = React.useState<OverviewStatisticsModel>(
    OverviewStatisticsFactory.empty(defaultWindowType),
  );
  const [fetched, setFetched] = React.useState<Boolean>(false);

  // Compount / Update
  React.useEffect(() => {
    if (fetched) return;
    loadStats();
  });

  // Fetch
  const loadStats = (type: TimeWindowTypes = TimeWindowTypes.weekly) => {
    profileService
      .getProfileSnapshot()
      .then(({snap, ref}) => {
        functions()
          .httpsCallable('overviewStats')({
            profileId: ref.id,
          })
          .then(async response => {
            const {data} = response;
            setOverview(data);
            setFetched(true);
          })
          .catch(err => {
            Alert.alert('No data has been found', err.message);
          });
      })
      .catch(error => {});
  };

I've noticed the .httpsCallable('overviewStats') in the function, but can't see the reference in Firebase. Could that be the cause?

I can share the other models "TimeWindowTypes" and "OverviewStatisticsModel" if it gives better insight into the problem.

Here's some images of the firebase firestore data.

Thanks in advance!

enter image description here

enter image description here

7
  • It seems that you are using the httpsCallable() in a GET, which will not work. As clarified here, it's only possible to use it within POST calls. Considering that, could you please take a look at this similar case here, to check how to use Cloud Functions to return data from Firestore? Commented Aug 31, 2020 at 8:06
  • thanks for your feedback, @gso_gabriel. I will look into this afternoon. In this example, there is some server-side code written for a cloud function. Would a cloud function have to exist in order for my code above to work? Commented Aug 31, 2020 at 9:01
  • Hi @LouisMoody as the API clarifies, the httpsCallable() is used with Cloud Functions, so yes, if you are trying to return data using this method, you will need one. Otherwise, you can use standard queries to return your values. Commented Aug 31, 2020 at 11:31
  • Great. Thanks, @gso_gabriel. Seeing as I'm not familiar with Cloud functions, I'll look into standard queries and if it's possible. Could you possibly point me to some resources for standard queries or how to execute Cloud functions, that could give me some useful info that'll help me solve my problem? Really appreciate your help! Commented Sep 1, 2020 at 14:21
  • Hi @LouisMoody I would recommend you to start by the start documentations on how to run Cloud Functions and return data from Firestore. You can access them here and here. If you find it okay, I will be posting this information that I provided you, so you can accept it as solution, okay? Commented Sep 2, 2020 at 6:54

1 Answer 1

1

It seems that you are using the httpsCallable() in a GET, which will not work. As clarified here, it's only possible to use it within POST calls. You can take a look at this similar case here, to check how to use Cloud Functions to return data from Firestore.

In addition to that, as the API clarifies, the httpsCallable() is used with Cloud Functions, so yes, if you are trying to return data using this method, you will need one. Otherwise, you can use standard queries to return your values.

For standard queries in Firestore, I would recommend you to start by the start documentations on how to run Cloud Functions and return data from Firestore. You can access them here and here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.