Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda