amazon-archives/amazon-cognito-js

Using CognitoSyncManager in a browser

mspiegle opened this issue · 5 comments

The docs seem to indicate that all I need to do is the following, but I receive an error:

  1. Include AWS SDK
  2. Include amazon-cognito-js via <script> tag
  3. Call the AWS.CognitoSyncManager() constructor

My test HTML file looks like this:

<!DOCTYPE html>
<html>
  <head>
    <script src="/js/aws-sdk-full-dev-2.7.20.js"></script>
    <script src="/js/amazon-cognito.min.js"></script>
    <script>
      var syncClient = new AWS.CognitoSyncManager();
    </script>
  </head>
</html>

The error in the dev console is:

amazon-cognito.min.js:35
Uncaught ReferenceError: require is not defined
    at amazon-cognito.min.js:35
    at amazon-cognito.min.js:13
    at amazon-cognito.min.js:15
(anonymous) @ amazon-cognito.min.js:35
(anonymous) @ amazon-cognito.min.js:13
(anonymous) @ amazon-cognito.min.js:15
test.html:7
Uncaught TypeError: AWS.CognitoSyncManager is not a constructor
    at test.html:7

If I add require.js to my list of includes, then the first error about "require is not defined" goes away, but the 2nd error about AWS.CognitoSyncManager remains.

Apologies for the issue, can you pull the latest code on github and retry?

Thanks for the quick response. That seems to have improved the situation slightly. The error about require is gone, but now I receive a new error. I used the amazon-cognito.min.js file directly from the dist/ directory:

amazon-cognito.min.js:35
Uncaught TypeError: Cannot read property 'params' of null
    at new AWS.CognitoSyncManager (amazon-cognito.min.js:35)
    at test.html:7

Yes, for that you would have to follow steps 2 and 3 from the README.

Sorry about that, I forgot to switch away from my minimal example back to my normal code. It appears to be working now. Thanks!

Thanks! Can you accept/close the issue on the AWS forums as well?