Make async function return a Promise

Viewed 64

I have an async function, which I want to return a promise. If I wrap it inside a promise, it says something like await has to be inside async function.

async function accessSpreadsheet(first_name,last_name,email,phone) {
  await doc.useServiceAccountAuth({
    client_email: creds.client_email,
    private_key: creds.private_key,
  });

  await doc.loadInfo(); // loads document properties and worksheets

  const sheet = doc.sheetsByIndex[0]; // or use doc.sheetsById[id]
  console.log(sheet.title);
  await sheet.addRow({ "first name": first_name,"last name": last_name, email: email,phone:phone });
}
0 Answers
Related