amazon-archives / aws-cognito-angular-quickstart

An Angular(v5)-based QuickStart single-page app utilizing Amazon Cognito, S3, and DynamoDB (Serverless architecture)
https://cognito.budilov.com
Apache License 2.0
689 stars 300 forks source link

Cannot read property 'ddb' of undefined #138

Open aaaguirrep opened 6 years ago

aaaguirrep commented 6 years ago

Hi, it is a good example of how to use aws cognito to users manage, I am beginning in the programming world and I am learning. I have tested the code and it is showing an issue in the console about "Cannot read property 'ddb' of undefined". I checked that it refers to aws.service.ts file and the line 95, there is a variable called ddb used. How and where should it be declared to remove the issue?

I have tried different ways and the issue doesn't disappear.

Thanks in advance.

I copy where the var is used.

addCognitoCredentials(idTokenJwt: string): void { let creds = this.cognitoUtil.buildCognitoCreds(idTokenJwt);

    AWS.config.credentials = creds;

    creds.get(function (err) {
        if (!err) {
            if (AwsUtil.firstLogin) {
                // save the login info to DDB
                this.ddb.writeLogEntry("login");
                AwsUtil.firstLogin = false;
            }
        }
    });
}
aaaguirrep commented 6 years ago

More information, the issue occurs when: -Login in the app -Close the tap -Open the app and it appears in the console.