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

236
Vistas
firestore database reference doesnt work with await

So I'm trying to use the twitter Api to test functionality and do specific tasks. I decided to use firestore to keep the relevant data. However when I create a database reference and try to use await later on in the code, it gives me an error. This is the code.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

const {Firestore} = require('@google-cloud/firestore');
const firestore = new firestore();
const dbRef = firestore.doc('tokens/demo');


const TwitterApi = require('twitter-api-v2').default;
const twitterClient = new TwitterApi({
  clientId: 'clientid',
  clientSecret: 'clientsecret',
});

const callbackURL = 'http://127.0.0.1:5001/twbt-ad868/us-central1/callback';

// STEP 1 - Auth URL
exports.auth = functions.https.onRequest((request, response) => {
    const { url, codeVerifier, state } = twitterClient.generateOAuth2AuthLink(
      callbackURL,
      { scope: ['tweet.read', 'tweet.write', 'users.read', 'offline.access'] }
    );
  
    // store verifier
    await dbRef.set({ codeVerifier, state });
  
    response.redirect(url);
  });

exports.callback = functions.https.onRequest((request, response) => {

});

exports.tweet = functions.https.onRequest((request, respone) => {});

and this is the error I get

await dbRef.set({ codeVerifier, state });
^^^^^

SyntaxError: await is only valid in async function

I've tried using this code instead to reference the json file in firestore, but I still get the same error

const dbRef = admin.firestore().doc('tokens/demo');

I'm assuming this is because my program isn't properly accessing the database in firestore? When I run this command

gcloud firestore operations list

I get

Listed 0 items.

If this is the case I'm not sure how to fix this and have my code access the database properly

Thank you in advance for any help you can provide me.

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

0

You must create an async function in order to have an await since it requires a promise.

async function () { await dbRef.set({ codeVerifier, state });}
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