slides-api icon indicating copy to clipboard operation
slides-api copied to clipboard

bug in storeToken()

Open sjbyrnes opened this issue 7 years ago • 1 comments

in auth.js:

If the TOKEN_DIR exists, the error will always be thrown and the token will never be stored.

function storeToken(token) {
  try {
    fs.mkdirSync(TOKEN_DIR);
    fs.writeFileSync(TOKEN_PATH, JSON.stringify(token));
  } catch (err) {
    if (err.code != 'EEXIST') return err;
  }
  console.log('Token stored to ' + TOKEN_PATH);
}

Should be:

function storeToken(token) {
    try {
        fs.mkdirSync(TOKEN_DIR);
    } catch (err) {
        if (err.code != 'EEXIST') return err;
    }
    try {
        fs.writeFileSync(TOKEN_PATH, JSON.stringify(token));
    } catch (err) {
        return err;
    }
    console.log('Token stored to ' + TOKEN_PATH);
}

sjbyrnes avatar Aug 21 '18 14:08 sjbyrnes

PRs welcome.

grant avatar Aug 07 '19 01:08 grant