amazon-archives / amazon-cognito-identity-js

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

React-Native: Cannot read property 'CognitoIdentityCredentials' of undefined #596

Closed dahudson88 closed 6 years ago

dahudson88 commented 6 years ago

Hello,

I am getting a Cannot read property 'CognitoIdentityCredentials' of undefined error when trying to get the credentials. I have aws-sdk installed. Is there something else that could be causing this issue?

See Code Below:

import { AWS } from 'aws-sdk'; import { CognitoUserPool, CognitoUserAttribute, CognitoUser, AuthenticationDetails } from 'amazon-cognito-identity-js';

loginUser() { const { navigate } = this.props.navigation; var authenticationData = { Username : this.state.emailText, Password : this.state.passwordText }; var authenticationDetails = new AuthenticationDetails(authenticationData);

var userData = {
    Username : this.state.emailText,
    Pool : userPool
};
var cognitoUser = new CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: function (result) {
        // console.log('access token + ' + result.getAccessToken().getJwtToken());

        **var creds = new AWS.CognitoIdentityCredentials({**
            IdentityPoolId : MATAppIdentityPool, // your identity pool id here
            Logins : {
                // Change the key below according to the specific region your user pool is in.
                idpURL: result.getIdToken().getJwtToken()
            }
        });
         onSignIn().then(() => navigate("SignedInNav", {authUser: cognitoUser}));
        // // Instantiate aws sdk service objects now that the credentials have been updated.
        // // example: var s3 = new AWS.S3();

    },

    onFailure: function(err) {
        alert(err);
    },

});
dahudson88 commented 6 years ago

This was my bad. Did not follow the instructions here https://www.npmjs.com/package/aws-sdk#in-react-native . Using import will not work be sure to do just as the instructions state.

itrestian commented 6 years ago

Yes, for now that is the way to bring in the main AWS SDK.