Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
Firebase callable functions. Promise is returning null on the client ( Cloud Functions )

I developed this firebase function to return data from my app search ( elastic ). When I log it at the functions console I can see the request data, and I can also see the response body at my App Search API Logs. But i can not get the data on the client

Response body


{
  "meta": {
    "alerts": [],
    "warnings": [],
    "precision": 2,
    "page": {
      "current": 1,
      "total_pages": 1,
      "total_results": 2,
      "size": 10
    },
    "engine": {
      "name": "engine",
      "type": "default"
    },
    "request_id": "DF4VEuzuQpWAHH8VCBkvDg"
  },
  "results": [
    {
      "nome": {
        "raw": "Produto legal"
      },
      "_meta": {
        "engine": "engine",
        "score": 0.8957006,
        "id": "bnxvuzVXIQ4BxqHxjvgt"
      },
      "id": {
        "raw": "bnxvuzVXIQ4BxqHxjvgt"
      }
    },
    {
      "nome": {
        "raw": "Produto massa"
      },
      "_meta": {
        "engine": "engine",
        "score": 0.3164503,
        "id": "rdG192xjSVCLIEBNg0la"
      },
      "id": {
        "raw": "rdG192xjSVCLIEBNg0la"
      }
    }
  ]
}

Firebase function


exports.searchProdutos = functions.https.onCall((data, context) => {
  const options = {
    search_fields: { nome: {} },
    result_fields: { nome: { raw: {} } },
  };
  const query = data.query;

  client
    .search("engine", `${query}`, options)
    .then((response) => {
      return response;
    })
    .catch((error) => console.log(error.errorMessages));
});

But when I try to call it in the client and log the response I get two null objects logged in the console

Function call on the client

  const searchProdutos = httpsCallable(functions, "searchProdutos");
  const getProdutos = async () => {
    const results = await searchProdutos({ query: "produto" });
    console.log(results.data);
  };
  getProdutos();

Aditional info: I am using Nodejs App Search in my functions and react as my frontend library/framework

Edit: I am also getting a 200 response. So I guess there is nothing wrong with the request. I tried removing the .then from my client function but I am still getting data: {null} twice

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I am posting a Community Wiki answer for this thread in order to have a solution available for future users. Based on the comments from Kevin B in the chatroom thread, there is a problem with the client side code which calls your Firebase function. When your client code logs the response with a then statement, this then statement does not return the response, but an undefined value, this makes the response get lost after being logged.

In addition, the server side Firebase function does not return the promise back to the client application inside the client.search() function. Based on the chatroom comments, your Firebase function should return the response from client.search().

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda