I am in a asynchronous function, trying to return the data from a callback function:
async function getData(){
const client = new google.auth.JWT(
keys.client_email,
null,
keys.private_key,
['https://www.googleapis.com/auth/spreadsheets']
)
let returnData
const finalData = (data) => {
returnData = data
}
async function gsrun(client) {
const gsapi = google.sheets({version:'v4', auth: client})
const options = {
spreadsheetId: '1d3ZiP1I9jJ2ddlD1Hx2ylWn1VFD_5lYQ9Ps9e9gEqI',
range: 'Sheet1!A1:H5'
}
const data = await gsapi.spreadsheets.values.get(options)
return data.data.values
}
client.authorize( async (err, tokens)=> {
if(err) return console.log(err)
let data = await gsrun(client)
finalData(data)
})
return returnData
}
And in the console I get: Promise { undefined }. How should I await that promise to resolve or to await the data?