amazon-archives / amazon-cognito-identity-js

Amazon Cognito Identity SDK for JavaScript
Other
986 stars 452 forks source link

NetworkingError: Cannot read property 'addEventListener' of undefined #574

Closed Octavic closed 6 years ago

Octavic commented 6 years ago

So I built a cognito web app using ReactCreateApp and this library. Everything works well, however, when I run a headless browser test, I receive the following error

{ NetworkingError: Cannot read property 'addEventListener' of undefined,
  ...
  message: 'Cannot read property \'addEventListener\' of undefined',
  code: 'NetworkingError'
}

Which is quite strange, because when I run the app in a real browser (Like chrome), it runs just fine. I'm able to access the same page and login with the same credentials. I suspect that it might have something to do with the somewhat janky local storage from headless browser testing, but I really have no idea.

The login code:

let authenticationData = {
  Username: username,
  Password: password
}
let authenticationDetails = new AuthenticationDetails(authenticationData)

let userData = {
   Username: username,
   Pool: this.userPool
}
this.cognitoUser = new CognitoUser(userData)

this.cognitoUser.authenticateUser(authenticationDetails, {
   onSuccess: function(result) {
     resolve(result)
  },
   onFailure: function(err) {
     console.log(err)
     reject(err.message)
  }
})

I'm using zombie.js for headless browser testing, and mocha as the test framework

Octavic commented 6 years ago

I added a lambda function that gets triggered for pre-authenticate. I noticed that the api is not even hitting the cognito endpoint. The error occurs locally somewhere, but I'm still unable to identify exactly where.

itrestian commented 6 years ago

Are you running your lambda inside a vpc that might not have access to hit the cognito endpoint?