0

I'm using "@react-native-firebase/firestore": "^23.1.1", "@react-native-firebase/functions": "23.1.1" "@react-native-firebase/app": "^23.1.1", on my expo client side code development build.

I tried to call my deployed cloud function like this but it throws this error:{"error": [Error: Could not connect to the server.]}

import { httpsCallable, getFunctions } from '@react-native-firebase/functions';

const functions = getFunctions();

const checkAuth = httpsCallable(functions, 'checkAuth');

// And then I have this onPress somewhere:
        onPress: async () => {
          try {
            const result = await checkAuth();
            console.log({ result: result.data });
            Alert.alert(
              'Success',
              `Operation successful! Fetched ${
                (result?.data as []).length
              } products.`,
            );
          } catch (error) {
            console.log({ error });
            Alert.alert('error', 'check error');
          }
        }

I'm using React-native-firebase SDK which does not require an initializeapp() call as it uses google-services.json and GoogleService-Info.plist for Android and IOS.

The cloud function is also deployed sucessfully on my firebase console at us-centrel (default).

expected to return the output I wrote for the cloud function. here's the actual function:

/**
 * Import function triggers from their respective submodules:
 *
 * import {onCall} from "firebase-functions/v2/https";
 * import {onDocumentWritten} from "firebase-functions/v2/firestore";
 *
 * See a full list of supported triggers at https://firebase.google.com/docs/functions
 */

import { setGlobalOptions } from 'firebase-functions';
import { onCall } from 'firebase-functions/v2/https';
import * as logger from 'firebase-functions/logger';

// The Firebase Admin SDK to access Firestore.
import { initializeApp } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';

// Start writing functions
// https://firebase.google.com/docs/functions/typescript

// For cost control, you can set the maximum number of containers that can be
// running at the same time. This helps mitigate the impact of unexpected
// traffic spikes by instead downgrading performance. This limit is a
// per-function limit. You can override the limit for each function using the
// `maxInstances` option in the function's options, e.g.
// `onRequest({ maxInstances: 5 }, (req, res) => { ... })`.
// NOTE: setGlobalOptions does not apply to functions using the v1 API. V1
// functions should each use functions.runWith({ maxInstances: 10 }) instead.
// In the v1 API, each function can only serve one request per container, so
// this will be the maximum concurrent request count.
setGlobalOptions({ maxInstances: 10 });
initializeApp();

exports.checkAuth = onCall(async (request, response) => {
  logger.info(request?.auth?.token);
  logger.info(request?.auth?.uid);

  return {
    auth: request.auth,
  };
});

update: update: httpsCallableFromUrl() works if I pass the URL to my cloud function, but httpsCallable() doesn't work, I'm not sure why const functions = getFunctions(); const checkAuth = httpsCallableFromUrl( functions, 'path-to-my-app.app', );

1 Answer 1

0

You can try to redownload the google-services.json and GoogleService-Info.plist and then rebuild your app

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

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

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.