From 53c91cbb61e79d8148949ec69c45fa9fd9f78553 Mon Sep 17 00:00:00 2001 From: powerful23 Date: Fri, 6 Apr 2018 11:29:51 -0700 Subject: [PATCH 1/2] mionr change --- packages/aws-amplify/src/Auth/Auth.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/aws-amplify/src/Auth/Auth.ts b/packages/aws-amplify/src/Auth/Auth.ts index d3633745332..300b10cfeb3 100644 --- a/packages/aws-amplify/src/Auth/Auth.ts +++ b/packages/aws-amplify/src/Auth/Auth.ts @@ -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 }; From a38827fc06d5e2efed6aed5ef8e4cb29613078ec Mon Sep 17 00:00:00 2001 From: powerful23 Date: Fri, 6 Apr 2018 14:36:15 -0700 Subject: [PATCH 2/2] add unit tests --- .../aws-amplify/__tests__/Auth/auth-unit-test.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/aws-amplify/__tests__/Auth/auth-unit-test.ts b/packages/aws-amplify/__tests__/Auth/auth-unit-test.ts index 46e4d4b558d..05514519641 100644 --- a/packages/aws-amplify/__tests__/Auth/auth-unit-test.ts +++ b/packages/aws-amplify/__tests__/Auth/auth-unit-test.ts @@ -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'}, @@ -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',