From 81ab1a613055b4b8795d5e87c64e8684f8201152 Mon Sep 17 00:00:00 2001 From: Max Davidson Date: Tue, 20 Feb 2018 10:56:30 +0100 Subject: [PATCH 1/6] Add .babelrc to .npmignore --- packages/amazon-cognito-identity-js/.npmignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/amazon-cognito-identity-js/.npmignore b/packages/amazon-cognito-identity-js/.npmignore index e69de29bb2d..ccf2c984f3e 100644 --- a/packages/amazon-cognito-identity-js/.npmignore +++ b/packages/amazon-cognito-identity-js/.npmignore @@ -0,0 +1,2 @@ +.babelrc + From 31045c2bfcbb5bdcd0d94b217c87f8fc990be698 Mon Sep 17 00:00:00 2001 From: Tim Roesner <13894518+timroesner@users.noreply.github.com> Date: Mon, 2 Apr 2018 19:26:27 -0700 Subject: [PATCH 2/6] Clarify alert message error --- packages/amazon-cognito-identity-js/README.md | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/amazon-cognito-identity-js/README.md b/packages/amazon-cognito-identity-js/README.md index 3ba7287468a..ee140d2f4d4 100644 --- a/packages/amazon-cognito-identity-js/README.md +++ b/packages/amazon-cognito-identity-js/README.md @@ -216,7 +216,7 @@ The usage examples below use the unqualified names for types in the Amazon Cogni userPool.signUp('username', 'password', attributeList, null, function(err, result){ if (err) { - alert(err); + alert(err.message); return; } cognitoUser = result.user; @@ -241,7 +241,7 @@ The usage examples below use the unqualified names for types in the Amazon Cogni var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData); cognitoUser.confirmRegistration('123456', true, function(err, result) { if (err) { - alert(err); + alert(err.message); return; } console.log('call result: ' + result); @@ -253,7 +253,7 @@ The usage examples below use the unqualified names for types in the Amazon Cogni ```javascript cognitoUser.resendConfirmationCode(function(err, result) { if (err) { - alert(err); + alert(err.message); return; } console.log('call result: ' + result); @@ -307,7 +307,7 @@ The usage examples below use the unqualified names for types in the Amazon Cogni }, onFailure: function(err) { - alert(err); + alert(err.message); }, }); @@ -322,7 +322,7 @@ Note also that if CognitoUser.authenticateUser throws ReferenceError: navigator ```javascript cognitoUser.getUserAttributes(function(err, result) { if (err) { - alert(err); + alert(err.message); return; } for (i = 0; i < result.length; i++) { @@ -341,7 +341,7 @@ Note that the inputVerificationCode method needs to be defined but does not need console.log('call result: ' + result); }, onFailure: function(err) { - alert(err); + alert(err.message); }, inputVerificationCode: function() { var verificationCode = prompt('Please input verification code: ' ,''); @@ -358,7 +358,7 @@ Note that the inputVerificationCode method needs to be defined but does not need cognitoUser.deleteAttributes(attributeList, function(err, result) { if (err) { - alert(err); + alert(err.message); return; } console.log('call result: ' + result); @@ -378,7 +378,7 @@ Note that the inputVerificationCode method needs to be defined but does not need cognitoUser.updateAttributes(attributeList, function(err, result) { if (err) { - alert(err); + alert(err.message); return; } console.log('call result: ' + result); @@ -390,7 +390,7 @@ Note that the inputVerificationCode method needs to be defined but does not need ```javascript cognitoUser.enableMFA(function(err, result) { if (err) { - alert(err); + alert(err.message); return; } console.log('call result: ' + result); @@ -402,7 +402,7 @@ Note that the inputVerificationCode method needs to be defined but does not need ```javascript cognitoUser.disableMFA(function(err, result) { if (err) { - alert(err); + alert(err.message); return; } console.log('call result: ' + result); @@ -414,7 +414,7 @@ Note that the inputVerificationCode method needs to be defined but does not need ```javascript cognitoUser.changePassword('oldPassword', 'newPassword', function(err, result) { if (err) { - alert(err); + alert(err.message); return; } console.log('call result: ' + result); @@ -430,7 +430,7 @@ Note that the inputVerificationCode method needs to be defined but does not need console.log('CodeDeliveryData from forgotPassword: ' + data); }, onFailure: function(err) { - alert(err); + alert(err.message); }, //Optional automatic callback inputVerificationCode: function(data) { @@ -456,7 +456,7 @@ Note that the inputVerificationCode method needs to be defined but does not need ```javascript cognitoUser.deleteUser(function(err, result) { if (err) { - alert(err); + alert(err.message); return; } console.log('call result: ' + result); @@ -508,7 +508,7 @@ In React Native, loading the persisted current user information requires an extr if (cognitoUser != null) { cognitoUser.getSession(function(err, session) { if (err) { - alert(err); + alert(err.message); return; } console.log('session validity: ' + session.isValid()); @@ -577,7 +577,7 @@ In React Native, loading the persisted current user information requires an extr console.log('call result: ' + result); }, onFailure: function(err) { - alert(err); + alert(err.message); } }); @@ -592,7 +592,7 @@ In React Native, loading the persisted current user information requires an extr console.log('call result: ' + result); }, onFailure: function(err) { - alert(err); + alert(err.message); } }); ``` @@ -607,7 +607,7 @@ In React Native, loading the persisted current user information requires an extr console.log('call result: ' + result); }, onFailure: function(err) { - alert(err); + alert(err.message); } }); ``` @@ -621,7 +621,7 @@ In React Native, loading the persisted current user information requires an extr console.log('call result: ' + result); }, onFailure: function(err) { - alert(err); + alert(err.message); } }); ``` @@ -636,7 +636,7 @@ In React Native, loading the persisted current user information requires an extr console.log('call result: ' + result); }, onFailure: function(err) { - alert(err); + alert(err.message); } }); ``` @@ -678,7 +678,7 @@ In React Native, loading the persisted current user information requires an extr ```javascript cognitoUser.getMFAOptions(function(err, mfaOptions) { if (err) { - alert(err); + alert(err.message); return; } console.log('MFA options for user ' + mfaOptions); @@ -758,7 +758,7 @@ The CookieStorage object receives a map (data) in its constructor that may have }, onFailure: function(err) { - alert(err); + alert(err.message); }, mfaSetup: function(challengeName, challengeParameters) { @@ -796,7 +796,7 @@ The CookieStorage object receives a map (data) in its constructor that may have }; cognitoUser.setUserMfaPreference(smsMfaSettings, null, function(err, result) { if (err) { - alert(err); + alert(err.message); } console.log('call result ' + result) }); @@ -811,7 +811,7 @@ The CookieStorage object receives a map (data) in its constructor that may have }; cognitoUser.setUserMfaPreference(null, totpMfaSettings, function(err, result) { if (err) { - alert(err); + alert(err.message); } console.log('call result ' + result) }); @@ -842,7 +842,7 @@ The CookieStorage object receives a map (data) in its constructor that may have ```js cognitoUser.getUserData(function(err, userData) { if (err) { - alert(err); + alert(err.message); return; } console.log('User data for user ' + userData); From def6345e725c068270ed6365e39ae67b670e53cf Mon Sep 17 00:00:00 2001 From: Murat Bahar Date: Fri, 6 Apr 2018 10:50:17 -0700 Subject: [PATCH 3/6] Update pub_sub_guide.md --- docs/media/pub_sub_guide.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/media/pub_sub_guide.md b/docs/media/pub_sub_guide.md index 5cb943d2f94..7e5409222b1 100644 --- a/docs/media/pub_sub_guide.md +++ b/docs/media/pub_sub_guide.md @@ -4,9 +4,9 @@ AWS Amplify PubSub module provides connectivity with cloud-based message-oriented middleware. You can use PubSub to pass messages between your app instances and your app's backend for creating real-time interactive experiences. -PubSub is available with **Generic MQTT Over WebSocket Provider** and AWS IoT *(Coming soon)*. +PubSub is available with **AWS IoT** and **Generic MQTT Over WebSocket Provider**. -When you use AWS IoT, AWS Amplify PubSub module will automatically sign your HTTP requests when sending your messages. +With AWS IoT, AWS Amplify PubSub module automatically signs your HTTP requests when sending your messages. {: .callout .callout--info} ## Installation and Configuration From 53c91cbb61e79d8148949ec69c45fa9fd9f78553 Mon Sep 17 00:00:00 2001 From: powerful23 Date: Fri, 6 Apr 2018 11:29:51 -0700 Subject: [PATCH 4/6] 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 1f56c74236d7f0e23b3e8f3ba58269f3e80eba91 Mon Sep 17 00:00:00 2001 From: Tim Roesner <13894518+timroesner@users.noreply.github.com> Date: Fri, 6 Apr 2018 12:58:12 -0700 Subject: [PATCH 5/6] Clarify error alert further --- packages/amazon-cognito-identity-js/README.md | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/amazon-cognito-identity-js/README.md b/packages/amazon-cognito-identity-js/README.md index ee140d2f4d4..22780d22e75 100644 --- a/packages/amazon-cognito-identity-js/README.md +++ b/packages/amazon-cognito-identity-js/README.md @@ -216,7 +216,7 @@ The usage examples below use the unqualified names for types in the Amazon Cogni userPool.signUp('username', 'password', attributeList, null, function(err, result){ if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } cognitoUser = result.user; @@ -241,7 +241,7 @@ The usage examples below use the unqualified names for types in the Amazon Cogni var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData); cognitoUser.confirmRegistration('123456', true, function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('call result: ' + result); @@ -253,7 +253,7 @@ The usage examples below use the unqualified names for types in the Amazon Cogni ```javascript cognitoUser.resendConfirmationCode(function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('call result: ' + result); @@ -307,7 +307,7 @@ The usage examples below use the unqualified names for types in the Amazon Cogni }, onFailure: function(err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); }, }); @@ -322,7 +322,7 @@ Note also that if CognitoUser.authenticateUser throws ReferenceError: navigator ```javascript cognitoUser.getUserAttributes(function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } for (i = 0; i < result.length; i++) { @@ -341,7 +341,7 @@ Note that the inputVerificationCode method needs to be defined but does not need console.log('call result: ' + result); }, onFailure: function(err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); }, inputVerificationCode: function() { var verificationCode = prompt('Please input verification code: ' ,''); @@ -358,7 +358,7 @@ Note that the inputVerificationCode method needs to be defined but does not need cognitoUser.deleteAttributes(attributeList, function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('call result: ' + result); @@ -378,7 +378,7 @@ Note that the inputVerificationCode method needs to be defined but does not need cognitoUser.updateAttributes(attributeList, function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('call result: ' + result); @@ -390,7 +390,7 @@ Note that the inputVerificationCode method needs to be defined but does not need ```javascript cognitoUser.enableMFA(function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('call result: ' + result); @@ -402,7 +402,7 @@ Note that the inputVerificationCode method needs to be defined but does not need ```javascript cognitoUser.disableMFA(function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('call result: ' + result); @@ -414,7 +414,7 @@ Note that the inputVerificationCode method needs to be defined but does not need ```javascript cognitoUser.changePassword('oldPassword', 'newPassword', function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('call result: ' + result); @@ -430,7 +430,7 @@ Note that the inputVerificationCode method needs to be defined but does not need console.log('CodeDeliveryData from forgotPassword: ' + data); }, onFailure: function(err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); }, //Optional automatic callback inputVerificationCode: function(data) { @@ -456,7 +456,7 @@ Note that the inputVerificationCode method needs to be defined but does not need ```javascript cognitoUser.deleteUser(function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('call result: ' + result); @@ -508,7 +508,7 @@ In React Native, loading the persisted current user information requires an extr if (cognitoUser != null) { cognitoUser.getSession(function(err, session) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('session validity: ' + session.isValid()); @@ -592,7 +592,7 @@ In React Native, loading the persisted current user information requires an extr console.log('call result: ' + result); }, onFailure: function(err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); } }); ``` @@ -607,7 +607,7 @@ In React Native, loading the persisted current user information requires an extr console.log('call result: ' + result); }, onFailure: function(err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); } }); ``` @@ -621,7 +621,7 @@ In React Native, loading the persisted current user information requires an extr console.log('call result: ' + result); }, onFailure: function(err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); } }); ``` @@ -636,7 +636,7 @@ In React Native, loading the persisted current user information requires an extr console.log('call result: ' + result); }, onFailure: function(err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); } }); ``` @@ -678,7 +678,7 @@ In React Native, loading the persisted current user information requires an extr ```javascript cognitoUser.getMFAOptions(function(err, mfaOptions) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('MFA options for user ' + mfaOptions); @@ -758,7 +758,7 @@ The CookieStorage object receives a map (data) in its constructor that may have }, onFailure: function(err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); }, mfaSetup: function(challengeName, challengeParameters) { @@ -796,7 +796,7 @@ The CookieStorage object receives a map (data) in its constructor that may have }; cognitoUser.setUserMfaPreference(smsMfaSettings, null, function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); } console.log('call result ' + result) }); @@ -811,7 +811,7 @@ The CookieStorage object receives a map (data) in its constructor that may have }; cognitoUser.setUserMfaPreference(null, totpMfaSettings, function(err, result) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); } console.log('call result ' + result) }); @@ -842,7 +842,7 @@ The CookieStorage object receives a map (data) in its constructor that may have ```js cognitoUser.getUserData(function(err, userData) { if (err) { - alert(err.message); + alert(err.message || JSON.stringify(err)); return; } console.log('User data for user ' + userData); From a38827fc06d5e2efed6aed5ef8e4cb29613078ec Mon Sep 17 00:00:00 2001 From: powerful23 Date: Fri, 6 Apr 2018 14:36:15 -0700 Subject: [PATCH 6/6] 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',