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

143
Visualizações
Cloud Function retrieving a value based on URL parameter

I am trying to write a Cloud Function in node where I can return a token from a parameter. The URL I use is... https://us-central1-nmnm03.cloudfunctions.net/GetAccount?taccount=Asd

my function is this... and its wrong. I suspect I am not assigning TT properly.

var functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.GetAccount = functions.https.onRequest((req, res) => {
        const t = admin.database().ref('/newaccout/'+req.query.account)
        const tt = t.child(token)
            res.send( "res is " + tt );
  });

req.query.account is the Key. One of the Items in the document is token ideally, I would like to get something like... {"token":"23453458885"}

Could I get a node hint please... thanks

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Though, I am not a firebase geek. What it seems from the documentation is that you will have two events that you can use to listen for retrieving child data. You can read further more here. The given options are used for different cases. Please follow through the mentioned link to have clear view.

Inside your cloud function you can try doing following:

const t = admin.database().ref('/newaccout/'+req.query.account)
t.on('child_added', function(data) {
  res.json({
     token: data.token
  })
})

Or maybe like this:

const t = admin.database().ref('/newaccout/'+req.query.account)
t.once('value', function(snapshot) {
   //Process it like above
   //But here you will get al child elements at once
});
about 4 years ago · Santiago Trujillo Relatório

0

It looks like you are expecting to query the value found at a database reference stored at t. Unfortunately, you haven't actually performed a query yet. tt is just yet another Reference object that points to a location in the database. You should use the once() method on Reference to query a database location. Also bear in mind that you are using a variable called token, but you haven't defined yet in your code. To me, that looks like it would generate an error to me.

You might be well served by looking at a bunch of the sample code.

about 4 years ago · Santiago Trujillo 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