Skip to content

Commit

Permalink
Merge branch 'master' into bug/cognito-js-network-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mlabieniec committed Apr 7, 2018
2 parents dc14b57 + 0cee8db commit 35e1758
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 32 deletions.
4 changes: 2 additions & 2 deletions docs/media/pub_sub_guide.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/amazon-cognito-identity-js/.npmignore
@@ -0,0 +1,2 @@
.babelrc

48 changes: 24 additions & 24 deletions packages/amazon-cognito-identity-js/README.md
Expand Up @@ -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 || JSON.stringify(err));
return;
}
cognitoUser = result.user;
Expand All @@ -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 || JSON.stringify(err));
return;
}
console.log('call result: ' + result);
Expand All @@ -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 || JSON.stringify(err));
return;
}
console.log('call result: ' + result);
Expand Down Expand Up @@ -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 || JSON.stringify(err));
},

});
Expand All @@ -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 || JSON.stringify(err));
return;
}
for (i = 0; i < result.length; i++) {
Expand All @@ -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 || JSON.stringify(err));
},
inputVerificationCode: function() {
var verificationCode = prompt('Please input verification code: ' ,'');
Expand All @@ -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 || JSON.stringify(err));
return;
}
console.log('call result: ' + result);
Expand All @@ -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 || JSON.stringify(err));
return;
}
console.log('call result: ' + result);
Expand All @@ -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 || JSON.stringify(err));
return;
}
console.log('call result: ' + result);
Expand All @@ -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 || JSON.stringify(err));
return;
}
console.log('call result: ' + result);
Expand All @@ -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 || JSON.stringify(err));
return;
}
console.log('call result: ' + result);
Expand All @@ -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 || JSON.stringify(err));
},
//Optional automatic callback
inputVerificationCode: function(data) {
Expand All @@ -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 || JSON.stringify(err));
return;
}
console.log('call result: ' + result);
Expand Down Expand Up @@ -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 || JSON.stringify(err));
return;
}
console.log('session validity: ' + session.isValid());
Expand Down Expand Up @@ -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);
}
});

Expand All @@ -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 || JSON.stringify(err));
}
});
```
Expand All @@ -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 || JSON.stringify(err));
}
});
```
Expand All @@ -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 || JSON.stringify(err));
}
});
```
Expand All @@ -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 || JSON.stringify(err));
}
});
```
Expand Down Expand Up @@ -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 || JSON.stringify(err));
return;
}
console.log('MFA options for user ' + mfaOptions);
Expand Down Expand Up @@ -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 || JSON.stringify(err));
},

mfaSetup: function(challengeName, challengeParameters) {
Expand Down Expand Up @@ -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 || JSON.stringify(err));
}
console.log('call result ' + result)
});
Expand All @@ -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 || JSON.stringify(err));
}
console.log('call result ' + result)
});
Expand Down Expand Up @@ -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 || JSON.stringify(err));
return;
}
console.log('User data for user ' + userData);
Expand Down
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 35e1758

Please sign in to comment.