`auth` must be present... error when calling function from another function
Opened this issue · 0 comments
nalloyd2 commented
Hi all. Just getting started with the JS SDK and having some trouble with authentication. I created a function that successfully returns the token based on UN + PW authentication. This function works fine if I run it directly, however I get the error in the title when I call the authentication function from within another function.
I tried adding the 'auth' param but get a login failed error when it's present. Any input is appreciated.
Auth Function
const pcloud = require('pcloud-sdk-js')
const app = require('./app.json');
global.locationid = 1;
async function getAuth() {
console.log('debug')
const params = {
getauth: true,
username: [REDACTED],
password: [REDACTED],
}
const options = {
method: 'get',
responsetype: 'json',
params: params
}
const result = await pcloud.ApiRequest('userinfo', options)
.then(result => {
console.log(result)
return result.auth
})
.catch(err => { console.log(err) });
}
getAuth()
Test Function
const pcloud = require('pcloud-sdk-js')
const app = require('./app.json');
const getAuth = require('./getAuth.js')
global.locationid = 1;
async function getExtractArchive() {
const auth = await getAuth
console.log(auth)
const params = {
fileid: 'test',
tofolderid: 'test'
}
const options = {
auth: auth,
params: params
}
const extractedArchive = await pcloud.ApiRequest('extractarchive', options)
if (extractedArchive.finshed == 'false') {
setTimeout(extractArchive, 10000)
} else {
console.log(extractedArchive)
return extractedArchive
}
}
getExtractArchive()