0

I have a simple https firebase cloud function which get all user doc from firestore but it actually give me error of

Received RST_STREAM with code 2 triggered by internal client error: Protocol error

This is my index file is I have initailized the app

import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import {helloWorld} from "./apis/recJobs";


// eslint-disable-next-line @typescript-eslint/no-var-requires
const serviceAccount = require("../serviceAccount.json");
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "*************",
});

// APIs
export const hello = functions.region(
    "asia-south1"
).https.onRequest(helloWorld);

This is my HelloWorld Function which is straight forward to get all docs from firestore

import * as admin from "firebase-admin";


export const helloWorld = (req :any, res:any) => {
  try {
    // get all users doc
    const db = admin.firestore();
    //  get all docs from user
    const snapshot = db.collection("user").get();
    snapshot.then((data) => {
      console.log("data is :", data);
      res.status(200).send({
        ok: "Success",
      });
    }
    ).catch((error) => {
      console.log("error is :", error);
      res.status(400).send({
        ok: error,
      });
    }
    );
  } catch (error) {
    console.log("error is :", error);
    res.status(400).send({
      ok: "Final error",
    });
  }
};

It should return all the user docs

0 Answers0