Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: await is only valid in async functions #1

Open
tobymac208 opened this issue Feb 3, 2022 · 8 comments
Open

SyntaxError: await is only valid in async functions #1

tobymac208 opened this issue Feb 3, 2022 · 8 comments

Comments

@tobymac208
Copy link

"Step 1" fails with error "SyntaxError: await is only valid in async functions and the top level bodies of modules":

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);
});

Please help.

@codewithpom
Copy link

But is supported in Node version later 14

@shaheerk1
Copy link

shaheerk1 commented Feb 4, 2022

Try adding "async" in front of the function keyword if you're using an older version of node js.

Edit : sorry, you shouldn't add "async" before the function keyword as we are using another arrow function after that.
So, the correct place to add async is before (request, response) => {}

@arifmamon
Copy link

But is supported in Node version later 14

v16.13.1
Still Problem ...

@AkshatRastogi-1nC0re
Copy link

I am facing the same issue. Any solutions yet ?

@PixelPasta
Copy link

Faced The Same Problem, add async after "onRequest("

exports.auth = functions.https.onRequest(async (req, res) => {

@JamesHWade
Copy link

I'm new to javascript. Would someone mind explaining why only step 1 needs async? Do they others need it to in the arrow functions?

@PixelPasta
Copy link

I had to add async to all 3 functions for it to work

@coffeepostal
Copy link

I'm having the same issue, I'll try adding async, but if someone knows how to change the project version of Node, that would be super helpful. I'm using N to version manage node, and v12 isn't one of the versions I have installed. When I run node --version I get the correct version. I'm assuming it's somewhere in the Firebase settings that needs to change, but I can't find where to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants