gpt3-twitter-bot
gpt3-twitter-bot copied to clipboard
SyntaxError: await is only valid in async functions
"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.
But is supported in Node version later 14
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) => {}
But is supported in Node version later 14
v16.13.1 Still Problem ...
I am facing the same issue. Any solutions yet ?
Faced The Same Problem, add async after "onRequest("
exports.auth = functions.https.onRequest(async (req, res) => {
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?
I had to add async to all 3 functions for it to work
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.