Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CognitoIdentityCredentials return session undefined #6

Closed
hszeto opened this issue Jun 1, 2017 · 1 comment
Closed

CognitoIdentityCredentials return session undefined #6

hszeto opened this issue Jun 1, 2017 · 1 comment

Comments

@hszeto
Copy link

hszeto commented Jun 1, 2017

I ran the app.js from the example locally. Cognito returns the access token. However, when console logging Config.credentials, I got the following:

CognitoIdentityCredentials {expired: true, expireTime: null, accessKeyId: undefined, sessionToken: undefined, params: Object…}
accessKeyId:undefined
data:null
expireTime:null
expired:true
params:Object
sessionToken:undefined
_clientConfig:Object
_identityId:null
identityId:(...)
secretAccessKey:undefined
get identityId:function get()
set identityId:function set(identityId)
proto:Credentials

How do I get a valid session when an user login ?

@jmparsons
Copy link
Contributor

jmparsons commented Jun 2, 2017

@hszeto It's all in the documentation Use case 16:

const cognitoUser = new CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
  onSuccess: (result) => {
    console.log('access token + ' + result.getAccessToken().getJwtToken());
    Config.credentials = new CognitoIdentityCredentials({
      IdentityPoolId: appConfig.IdentityPoolId,
      Logins: {
        [`cognito-idp.${appConfig.region}.amazonaws.com/${appConfig.UserPoolId}`]: result.getIdToken().getJwtToken()
      }
    });
    alert('Success');
    console.log(Config.credentials);
    //now user is logged in - can get session here
    cognitoUser.getSession((error, result) => {
      if (error) {
        console.log(error);
      } else {
        console.log(result);
      }
    });
  },
  onFailure: (err) => {
    alert(err);
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants