Skip to content

Commit

Permalink
Merge pull request #608 from powerful23/auth-currentUserInfo-fix
Browse files Browse the repository at this point in the history
Auth current user info fix
  • Loading branch information
powerful23 committed Apr 7, 2018
2 parents 2a1428d + 3093bfd commit 0cee8db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/aws-amplify/__tests__/Auth/auth-unit-test.ts
Expand Up @@ -1378,11 +1378,6 @@ describe('auth unit test', () => {

const spyon2 = jest.spyOn(Auth.prototype, 'userAttributes')
.mockImplementationOnce(() => {
auth['credentials'] = new CognitoIdentityCredentials({
IdentityPoolId: 'identityPoolId',
IdentityId: 'identityId'
});
auth['credentials']['identityId'] = 'identityId';
return new Promise((res, rej)=> {
res([
{Name: 'email', Value: 'email'},
Expand All @@ -1394,6 +1389,13 @@ describe('auth unit test', () => {
});
});

const spyon3 = jest.spyOn(Auth.prototype, 'currentCredentials').mockImplementationOnce(() => {
auth['credentials'] = {
identityId: 'identityId'
}
return Promise.resolve();
});

expect.assertions(1);
expect(await auth.currentUserInfo()).toEqual({
username: 'username',
Expand Down
11 changes: 10 additions & 1 deletion packages/aws-amplify/src/Auth/Auth.ts
Expand Up @@ -977,8 +977,17 @@ export default class AuthClass {
const attributes = await this.userAttributes(user);
const userAttrs:object = this.attributesToObject(attributes);

// check if the credentials is in the memory
if (!this.credentials) {
try {
await this.currentCredentials();
} catch (e) {
logger.debug('Failed to retrieve credentials while getting current user info', e);
}
}

const info = {
'id': this.credentials.identityId,
'id': this.credentials? this.credentials.identityId : undefined,
'username': user.username,
'attributes': userAttrs
};
Expand Down

0 comments on commit 0cee8db

Please sign in to comment.