Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!