Implementing AWS-Cognito in Angular 2

Viewed 11104

I'm currently trying to get into building webapps with Angular and AWS. My first step is to get working authentication using AWS-Cognito. But i've run in to some problems with imporing and using the AWS-Cognito SDK.

I have taken the following steps:

I started by using this Angular 2 quickstart to set up my app: https://github.com/angular/quickstart and then ran npm install

My next step was to install angular CLI with npm install -g @angular/cli

Next I installed angular-cognito-identity-sdk by running: npm install --save amazon-cognito-identity-js

After the SDK was installed I required the sdk into my component:

 console.log(AmazonCognitoIdentity);

         var authenticationData = {
            Username : 'username',
            Password : 'password',
        };
        var authenticationDetails = new AmazonCognitoIdentity.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
        var poolData = {
            UserPoolId : 'pool_id', // Your user pool id here
            ClientId : 'client_id' // Your client id here
        };
        var userPool = new AmazonCognitoIdentity.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
        var userData = {
            Username : 'username',
            Pool : userPool
        };

But when I run the code Iäm given the following error:

TypeError: Cannot read property 'AuthenticationDetails' of undefined

Am I missing a step here? What is the best way to implement the Cognito SDK in my Angular app?

Thank you!

2 Answers
Related