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

auth must be present... error when calling function from another function #51

Open
nalloyd2 opened this issue May 27, 2022 · 0 comments

Comments

@nalloyd2
Copy link

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()
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

No branches or pull requests

1 participant