tonwayer / issues

0 stars 0 forks source link

How to implement AWS cognito with Vanilla JavaScript? #1

Open tonwayer opened 2 years ago

tonwayer commented 2 years ago

Hi, @ajhool

I hope this issue finds you. I am trying to implement AWS cognito with Vanilla JavaScript (federatedSignIn with google). Fortunately I found out your issue Is Amplify compatible with a vanilla javascript + HTML client-side static website?. But I can't find the solution from it. Would you provide sample code or documentation?

ajhool commented 2 years ago

Hi @tonwayer , I don't have documentation as this was a long time ago. However, based on my memory and comments in that issue, the solution was to:

  1. Create a nodejs project
  2. Install the amplify frontend package (I forget the name of the package, but something like yarn add aws-amplify
  3. The node_modules/amplify folder would have an index.js file which contains the entire amplify code.
  4. Copy and paste that index.js file into your vanilla javascript project. Import it using the standard local <script> javascript importing tag
  5. At that point, you would have imported Amplify into your javascript project and could use the functions like normal (eg. Amplify.init() and Auth.signIn()