getstation / electron-google-oauth2

A Google OAuth2 module for your Electron app
MIT License
79 stars 38 forks source link

__awaiter is not defined #9

Closed baruchiro closed 4 years ago

baruchiro commented 4 years ago

Hi, I have an Electron + Vue project (no TypeScript), and when I trying to use your library, I'm getting the next error when I trying to openAuthWindowAndGetTokens:

ReferenceError: __awaiter is not defined at ElectronGoogleOAuth2.openAuthPageAndGetAuthorizationCode (index.js?0322:85) at ElectronGoogleOAuth2.openAuthWindowAndGetAuthorizationCode (index.js?0322:82) at ElectronGoogleOAuth2.getAuthorizationCode (index.js?0322:74) at ElectronGoogleOAuth2.openAuthWindowAndGetTokens (index.js?0322:122) at _callee4$ (index.js?f1e9:22) at tryCatch (runtime.js?96cf:62) at Generator.invoke [as _invoke] (runtime.js?96cf:296) at Generator.prototype.(:8081/anonymous function) [as next] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:114:21) at asyncGeneratorStep (asyncToGenerator.js?1da1:3) at _next (asyncToGenerator.js?1da1:25)

My code:

const clientDetails = require('./client_secret.json');
const myApiOauth = new ElectronGoogleOAuth2(
  clientDetails.client_id,
  clientDetails.client_secret,
  [
    'https://www.googleapis.com/auth/drive.metadata.readonly',
    'https://www.googleapis.com/auth/spreadsheets',
  ],
);

myApiOauth.on('tokens', async (tokens) => {
  if (tokens.refresh_token) {
    await saveToken(tokens);
  }
});

const savedToken = await loadToken();

if (savedToken !== null) {
  myApiOauth.setTokens(savedToken);
} else {
  try {
    const token = await myApiOauth.openAuthWindowAndGetTokens();
    await saveToken(token);
    myApiOauth.setTokens(token);
  } catch (err) {
    debugger;
    console.error(err);
  }
}

So I copied your code and removed all TypeScript references, and it works. You can use this commit from my PR to reproduce the bug, just install your package with yarn and change the import: https://github.com/baruchiro/israeli-bank-scrapers-desktop/blob/81792211d4dd8650f4a85d3aa37b39fdb636380a/src/modules/googleOauth/index.js#L1

magne4000 commented 4 years ago

@baruchiro I released a new version that should fix your issue, could you try it?

baruchiro commented 4 years ago

Thanks! It solved!