@aws-amplify/auth 4.3.19 → 4.3.20-custom-pk.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3964,20 +3964,8 @@ module.exports = function(module) {
3964
3964
  __webpack_require__.r(__webpack_exports__);
3965
3965
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return AuthenticationDetails; });
3966
3966
  /*!
3967
- * Copyright 2016 Amazon.com,
3968
- * Inc. or its affiliates. All Rights Reserved.
3969
- *
3970
- * Licensed under the Amazon Software License (the "License").
3971
- * You may not use this file except in compliance with the
3972
- * License. A copy of the License is located at
3973
- *
3974
- * http://aws.amazon.com/asl/
3975
- *
3976
- * or in the "license" file accompanying this file. This file is
3977
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
3978
- * CONDITIONS OF ANY KIND, express or implied. See the License
3979
- * for the specific language governing permissions and
3980
- * limitations under the License.
3967
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3968
+ * SPDX-License-Identifier: Apache-2.0
3981
3969
  */
3982
3970
 
3983
3971
  /** @class */
@@ -4077,20 +4065,8 @@ __webpack_require__.r(__webpack_exports__);
4077
4065
  /* harmony import */ var _utils_WordArray__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./utils/WordArray */ "../amazon-cognito-identity-js/es/utils/WordArray.js");
4078
4066
  /* harmony import */ var _BigInteger__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./BigInteger */ "../amazon-cognito-identity-js/es/BigInteger.js");
4079
4067
  /*!
4080
- * Copyright 2016 Amazon.com,
4081
- * Inc. or its affiliates. All Rights Reserved.
4082
- *
4083
- * Licensed under the Amazon Software License (the "License").
4084
- * You may not use this file except in compliance with the
4085
- * License. A copy of the License is located at
4086
- *
4087
- * http://aws.amazon.com/asl/
4088
- *
4089
- * or in the "license" file accompanying this file. This file is
4090
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
4091
- * CONDITIONS OF ANY KIND, express or implied. See the License
4092
- * for the specific language governing permissions and
4093
- * limitations under the License.
4068
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4069
+ * SPDX-License-Identifier: Apache-2.0
4094
4070
  */
4095
4071
 
4096
4072
 
@@ -5410,7 +5386,7 @@ function _wrapNativeSuper(Class) {
5410
5386
 
5411
5387
  function _construct(Parent, args, Class) {
5412
5388
  if (_isNativeReflectConstruct()) {
5413
- _construct = Reflect.construct;
5389
+ _construct = Reflect.construct.bind();
5414
5390
  } else {
5415
5391
  _construct = function _construct(Parent, args, Class) {
5416
5392
  var a = [null];
@@ -5443,16 +5419,15 @@ function _isNativeFunction(fn) {
5443
5419
  }
5444
5420
 
5445
5421
  function _setPrototypeOf(o, p) {
5446
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
5422
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
5447
5423
  o.__proto__ = p;
5448
5424
  return o;
5449
5425
  };
5450
-
5451
5426
  return _setPrototypeOf(o, p);
5452
5427
  }
5453
5428
 
5454
5429
  function _getPrototypeOf(o) {
5455
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
5430
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
5456
5431
  return o.__proto__ || Object.getPrototypeOf(o);
5457
5432
  };
5458
5433
  return _getPrototypeOf(o);
@@ -5720,28 +5695,15 @@ function _inheritsLoose(subClass, superClass) {
5720
5695
  }
5721
5696
 
5722
5697
  function _setPrototypeOf(o, p) {
5723
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
5698
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
5724
5699
  o.__proto__ = p;
5725
5700
  return o;
5726
5701
  };
5727
-
5728
5702
  return _setPrototypeOf(o, p);
5729
5703
  }
5730
- /*
5731
- * Copyright 2016 Amazon.com,
5732
- * Inc. or its affiliates. All Rights Reserved.
5733
- *
5734
- * Licensed under the Amazon Software License (the "License").
5735
- * You may not use this file except in compliance with the
5736
- * License. A copy of the License is located at
5737
- *
5738
- * http://aws.amazon.com/asl/
5739
- *
5740
- * or in the "license" file accompanying this file. This file is
5741
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
5742
- * CONDITIONS OF ANY KIND, express or implied. See the License
5743
- * for the specific language governing permissions and
5744
- * limitations under the License.
5704
+ /*!
5705
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5706
+ * SPDX-License-Identifier: Apache-2.0
5745
5707
  */
5746
5708
 
5747
5709
 
@@ -5789,28 +5751,15 @@ function _inheritsLoose(subClass, superClass) {
5789
5751
  }
5790
5752
 
5791
5753
  function _setPrototypeOf(o, p) {
5792
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
5754
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
5793
5755
  o.__proto__ = p;
5794
5756
  return o;
5795
5757
  };
5796
-
5797
5758
  return _setPrototypeOf(o, p);
5798
5759
  }
5799
5760
  /*!
5800
- * Copyright 2016 Amazon.com,
5801
- * Inc. or its affiliates. All Rights Reserved.
5802
- *
5803
- * Licensed under the Amazon Software License (the "License").
5804
- * You may not use this file except in compliance with the
5805
- * License. A copy of the License is located at
5806
- *
5807
- * http://aws.amazon.com/asl/
5808
- *
5809
- * or in the "license" file accompanying this file. This file is
5810
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
5811
- * CONDITIONS OF ANY KIND, express or implied. See the License
5812
- * for the specific language governing permissions and
5813
- * limitations under the License.
5761
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5762
+ * SPDX-License-Identifier: Apache-2.0
5814
5763
  */
5815
5764
 
5816
5765
 
@@ -5852,20 +5801,8 @@ __webpack_require__.r(__webpack_exports__);
5852
5801
  /* harmony import */ var buffer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! buffer */ "../../node_modules/buffer/index.js");
5853
5802
  /* harmony import */ var buffer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(buffer__WEBPACK_IMPORTED_MODULE_0__);
5854
5803
  /*!
5855
- * Copyright 2016 Amazon.com,
5856
- * Inc. or its affiliates. All Rights Reserved.
5857
- *
5858
- * Licensed under the Amazon Software License (the "License").
5859
- * You may not use this file except in compliance with the
5860
- * License. A copy of the License is located at
5861
- *
5862
- * http://aws.amazon.com/asl/
5863
- *
5864
- * or in the "license" file accompanying this file. This file is
5865
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
5866
- * CONDITIONS OF ANY KIND, express or implied. See the License
5867
- * for the specific language governing permissions and
5868
- * limitations under the License.
5804
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5805
+ * SPDX-License-Identifier: Apache-2.0
5869
5806
  */
5870
5807
 
5871
5808
  /** @class */
@@ -5939,20 +5876,8 @@ var CognitoJwtToken = /*#__PURE__*/function () {
5939
5876
  __webpack_require__.r(__webpack_exports__);
5940
5877
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return CognitoRefreshToken; });
5941
5878
  /*!
5942
- * Copyright 2016 Amazon.com,
5943
- * Inc. or its affiliates. All Rights Reserved.
5944
- *
5945
- * Licensed under the Amazon Software License (the "License").
5946
- * You may not use this file except in compliance with the
5947
- * License. A copy of the License is located at
5948
- *
5949
- * http://aws.amazon.com/asl/
5950
- *
5951
- * or in the "license" file accompanying this file. This file is
5952
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
5953
- * CONDITIONS OF ANY KIND, express or implied. See the License
5954
- * for the specific language governing permissions and
5955
- * limitations under the License.
5879
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5880
+ * SPDX-License-Identifier: Apache-2.0
5956
5881
  */
5957
5882
 
5958
5883
  /** @class */
@@ -6016,20 +5941,8 @@ __webpack_require__.r(__webpack_exports__);
6016
5941
  /* harmony import */ var _CognitoUserAttribute__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./CognitoUserAttribute */ "../amazon-cognito-identity-js/es/CognitoUserAttribute.js");
6017
5942
  /* harmony import */ var _StorageHelper__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./StorageHelper */ "../amazon-cognito-identity-js/es/StorageHelper.js");
6018
5943
  /*!
6019
- * Copyright 2016 Amazon.com,
6020
- * Inc. or its affiliates. All Rights Reserved.
6021
- *
6022
- * Licensed under the Amazon Software License (the "License").
6023
- * You may not use this file except in compliance with the
6024
- * License. A copy of the License is located at
6025
- *
6026
- * http://aws.amazon.com/asl/
6027
- *
6028
- * or in the "license" file accompanying this file. This file is
6029
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
6030
- * CONDITIONS OF ANY KIND, express or implied. See the License
6031
- * for the specific language governing permissions and
6032
- * limitations under the License.
5944
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5945
+ * SPDX-License-Identifier: Apache-2.0
6033
5946
  */
6034
5947
 
6035
5948
 
@@ -8137,20 +8050,8 @@ var CognitoUser = /*#__PURE__*/function () {
8137
8050
  __webpack_require__.r(__webpack_exports__);
8138
8051
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return CognitoUserAttribute; });
8139
8052
  /*!
8140
- * Copyright 2016 Amazon.com,
8141
- * Inc. or its affiliates. All Rights Reserved.
8142
- *
8143
- * Licensed under the Amazon Software License (the "License").
8144
- * You may not use this file except in compliance with the
8145
- * License. A copy of the License is located at
8146
- *
8147
- * http://aws.amazon.com/asl/
8148
- *
8149
- * or in the "license" file accompanying this file. This file is
8150
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8151
- * CONDITIONS OF ANY KIND, express or implied. See the License
8152
- * for the specific language governing permissions and
8153
- * limitations under the License.
8053
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
8054
+ * SPDX-License-Identifier: Apache-2.0
8154
8055
  */
8155
8056
 
8156
8057
  /** @class */
@@ -8249,20 +8150,8 @@ __webpack_require__.r(__webpack_exports__);
8249
8150
  /* harmony import */ var _CognitoUser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./CognitoUser */ "../amazon-cognito-identity-js/es/CognitoUser.js");
8250
8151
  /* harmony import */ var _StorageHelper__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./StorageHelper */ "../amazon-cognito-identity-js/es/StorageHelper.js");
8251
8152
  /*!
8252
- * Copyright 2016 Amazon.com,
8253
- * Inc. or its affiliates. All Rights Reserved.
8254
- *
8255
- * Licensed under the Amazon Software License (the "License").
8256
- * You may not use this file except in compliance with the
8257
- * License. A copy of the License is located at
8258
- *
8259
- * http://aws.amazon.com/asl/
8260
- *
8261
- * or in the "license" file accompanying this file. This file is
8262
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8263
- * CONDITIONS OF ANY KIND, express or implied. See the License
8264
- * for the specific language governing permissions and
8265
- * limitations under the License.
8153
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
8154
+ * SPDX-License-Identifier: Apache-2.0
8266
8155
  */
8267
8156
 
8268
8157
 
@@ -8463,20 +8352,8 @@ var CognitoUserPool = /*#__PURE__*/function () {
8463
8352
  __webpack_require__.r(__webpack_exports__);
8464
8353
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return CognitoUserSession; });
8465
8354
  /*!
8466
- * Copyright 2016 Amazon.com,
8467
- * Inc. or its affiliates. All Rights Reserved.
8468
- *
8469
- * Licensed under the Amazon Software License (the "License").
8470
- * You may not use this file except in compliance with the
8471
- * License. A copy of the License is located at
8472
- *
8473
- * http://aws.amazon.com/asl/
8474
- *
8475
- * or in the "license" file accompanying this file. This file is
8476
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8477
- * CONDITIONS OF ANY KIND, express or implied. See the License
8478
- * for the specific language governing permissions and
8479
- * limitations under the License.
8355
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
8356
+ * SPDX-License-Identifier: Apache-2.0
8480
8357
  */
8481
8358
 
8482
8359
  /** @class */
@@ -8725,20 +8602,8 @@ var CookieStorage = /*#__PURE__*/function () {
8725
8602
  __webpack_require__.r(__webpack_exports__);
8726
8603
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return DateHelper; });
8727
8604
  /*!
8728
- * Copyright 2016 Amazon.com,
8729
- * Inc. or its affiliates. All Rights Reserved.
8730
- *
8731
- * Licensed under the Amazon Software License (the "License").
8732
- * You may not use this file except in compliance with the
8733
- * License. A copy of the License is located at
8734
- *
8735
- * http://aws.amazon.com/asl/
8736
- *
8737
- * or in the "license" file accompanying this file. This file is
8738
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8739
- * CONDITIONS OF ANY KIND, express or implied. See the License
8740
- * for the specific language governing permissions and
8741
- * limitations under the License.
8605
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
8606
+ * SPDX-License-Identifier: Apache-2.0
8742
8607
  */
8743
8608
  var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
8744
8609
  var weekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
@@ -8800,17 +8665,9 @@ __webpack_require__.r(__webpack_exports__);
8800
8665
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Platform", function() { return Platform; });
8801
8666
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getUserAgent", function() { return getUserAgent; });
8802
8667
  /* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./version */ "../amazon-cognito-identity-js/es/Platform/version.js");
8803
- /*
8804
- * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
8805
- *
8806
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
8807
- * the License. A copy of the License is located at
8808
- *
8809
- * http://aws.amazon.com/apache2.0/
8810
- *
8811
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8812
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
8813
- * and limitations under the License.
8668
+ /*!
8669
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
8670
+ * SPDX-License-Identifier: Apache-2.0
8814
8671
  */
8815
8672
 
8816
8673
  var BASE_USER_AGENT = "aws-amplify/" + _version__WEBPACK_IMPORTED_MODULE_0__["version"];
@@ -8876,20 +8733,8 @@ __webpack_require__.r(__webpack_exports__);
8876
8733
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MemoryStorage", function() { return MemoryStorage; });
8877
8734
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return StorageHelper; });
8878
8735
  /*!
8879
- * Copyright 2016 Amazon.com,
8880
- * Inc. or its affiliates. All Rights Reserved.
8881
- *
8882
- * Licensed under the Amazon Software License (the "License").
8883
- * You may not use this file except in compliance with the
8884
- * License. A copy of the License is located at
8885
- *
8886
- * http://aws.amazon.com/asl/
8887
- *
8888
- * or in the "license" file accompanying this file. This file is
8889
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8890
- * CONDITIONS OF ANY KIND, express or implied. See the License
8891
- * for the specific language governing permissions and
8892
- * limitations under the License.
8736
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
8737
+ * SPDX-License-Identifier: Apache-2.0
8893
8738
  */
8894
8739
  var dataMemory = {};
8895
8740
  /** @class */
@@ -9061,20 +8906,8 @@ __webpack_require__.r(__webpack_exports__);
9061
8906
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "WordArray", function() { return _utils_WordArray__WEBPACK_IMPORTED_MODULE_12__["default"]; });
9062
8907
 
9063
8908
  /*!
9064
- * Copyright 2016 Amazon.com,
9065
- * Inc. or its affiliates. All Rights Reserved.
9066
- *
9067
- * Licensed under the Amazon Software License (the "License").
9068
- * You may not use this file except in compliance with the
9069
- * License. A copy of the License is located at
9070
- *
9071
- * http://aws.amazon.com/asl/
9072
- *
9073
- * or in the "license" file accompanying this file. This file is
9074
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9075
- * CONDITIONS OF ANY KIND, express or implied. See the License
9076
- * for the specific language governing permissions and
9077
- * limitations under the License.
8909
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
8910
+ * SPDX-License-Identifier: Apache-2.0
9078
8911
  */
9079
8912
 
9080
8913
 
@@ -11487,21 +11320,68 @@ function () {
11487
11320
 
11488
11321
  var bypassCache = params ? params.bypassCache : false;
11489
11322
  user.getUserData(function (err, data) {
11490
- if (err) {
11491
- logger.debug('getting preferred mfa failed', err);
11492
- rej(err);
11493
- return;
11494
- }
11323
+ return __awaiter(_this, void 0, void 0, function () {
11324
+ var cleanUpError_1, mfaType;
11325
+ return __generator(this, function (_a) {
11326
+ switch (_a.label) {
11327
+ case 0:
11328
+ if (!err) return [3
11329
+ /*break*/
11330
+ , 5];
11331
+ logger.debug('getting preferred mfa failed', err);
11332
+ if (!this.isSessionInvalid(err)) return [3
11333
+ /*break*/
11334
+ , 4];
11335
+ _a.label = 1;
11495
11336
 
11496
- var mfaType = that._getMfaTypeFromUserData(data);
11337
+ case 1:
11338
+ _a.trys.push([1, 3,, 4]);
11497
11339
 
11498
- if (!mfaType) {
11499
- rej('invalid MFA Type');
11500
- return;
11501
- } else {
11502
- res(mfaType);
11503
- return;
11504
- }
11340
+ return [4
11341
+ /*yield*/
11342
+ , this.cleanUpInvalidSession(user)];
11343
+
11344
+ case 2:
11345
+ _a.sent();
11346
+
11347
+ return [3
11348
+ /*break*/
11349
+ , 4];
11350
+
11351
+ case 3:
11352
+ cleanUpError_1 = _a.sent();
11353
+ rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_1.message));
11354
+ return [2
11355
+ /*return*/
11356
+ ];
11357
+
11358
+ case 4:
11359
+ rej(err);
11360
+ return [2
11361
+ /*return*/
11362
+ ];
11363
+
11364
+ case 5:
11365
+ mfaType = that._getMfaTypeFromUserData(data);
11366
+
11367
+ if (!mfaType) {
11368
+ rej('invalid MFA Type');
11369
+ return [2
11370
+ /*return*/
11371
+ ];
11372
+ } else {
11373
+ res(mfaType);
11374
+ return [2
11375
+ /*return*/
11376
+ ];
11377
+ }
11378
+
11379
+ return [2
11380
+ /*return*/
11381
+ ];
11382
+ }
11383
+ });
11384
+ });
11505
11385
  }, {
11506
11386
  bypassCache: bypassCache,
11507
11387
  clientMetadata: clientMetadata
@@ -11543,16 +11423,62 @@ function () {
11543
11423
  };
11544
11424
 
11545
11425
  AuthClass.prototype._getUserData = function (user, params) {
11426
+ var _this = this;
11427
+
11546
11428
  return new Promise(function (res, rej) {
11547
11429
  user.getUserData(function (err, data) {
11548
- if (err) {
11549
- logger.debug('getting user data failed', err);
11550
- rej(err);
11551
- return;
11552
- } else {
11553
- res(data);
11554
- return;
11555
- }
11430
+ return __awaiter(_this, void 0, void 0, function () {
11431
+ var cleanUpError_2;
11432
+ return __generator(this, function (_a) {
11433
+ switch (_a.label) {
11434
+ case 0:
11435
+ if (!err) return [3
11436
+ /*break*/
11437
+ , 5];
11438
+ logger.debug('getting user data failed', err);
11439
+ if (!this.isSessionInvalid(err)) return [3
11440
+ /*break*/
11441
+ , 4];
11442
+ _a.label = 1;
11443
+
11444
+ case 1:
11445
+ _a.trys.push([1, 3,, 4]);
11446
+
11447
+ return [4
11448
+ /*yield*/
11449
+ , this.cleanUpInvalidSession(user)];
11450
+
11451
+ case 2:
11452
+ _a.sent();
11453
+
11454
+ return [3
11455
+ /*break*/
11456
+ , 4];
11457
+
11458
+ case 3:
11459
+ cleanUpError_2 = _a.sent();
11460
+ rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_2.message));
11461
+ return [2
11462
+ /*return*/
11463
+ ];
11464
+
11465
+ case 4:
11466
+ rej(err);
11467
+ return [2
11468
+ /*return*/
11469
+ ];
11470
+
11471
+ case 5:
11472
+ res(data);
11473
+ _a.label = 6;
11474
+
11475
+ case 6:
11476
+ return [2
11477
+ /*return*/
11478
+ ];
11479
+ }
11480
+ });
11481
+ });
11556
11482
  }, params);
11557
11483
  });
11558
11484
  };
@@ -11568,6 +11494,8 @@ function () {
11568
11494
  return __awaiter(this, void 0, void 0, function () {
11569
11495
  var clientMetadata, userData, smsMfaSettings, totpMfaSettings, _a, mfaList, currentMFAType, that;
11570
11496
 
11497
+ var _this = this;
11498
+
11571
11499
  return __generator(this, function (_b) {
11572
11500
  switch (_b.label) {
11573
11501
  case 0:
@@ -11707,12 +11635,53 @@ function () {
11707
11635
  logger.debug('Caching the latest user data into local'); // cache the latest result into user data
11708
11636
 
11709
11637
  user.getUserData(function (err, data) {
11710
- if (err) {
11711
- logger.debug('getting user data failed', err);
11712
- return rej(err);
11713
- } else {
11714
- return res(result);
11715
- }
11638
+ return __awaiter(_this, void 0, void 0, function () {
11639
+ var cleanUpError_3;
11640
+ return __generator(this, function (_a) {
11641
+ switch (_a.label) {
11642
+ case 0:
11643
+ if (!err) return [3
11644
+ /*break*/
11645
+ , 5];
11646
+ logger.debug('getting user data failed', err);
11647
+ if (!this.isSessionInvalid(err)) return [3
11648
+ /*break*/
11649
+ , 4];
11650
+ _a.label = 1;
11651
+
11652
+ case 1:
11653
+ _a.trys.push([1, 3,, 4]);
11654
+
11655
+ return [4
11656
+ /*yield*/
11657
+ , this.cleanUpInvalidSession(user)];
11658
+
11659
+ case 2:
11660
+ _a.sent();
11661
+
11662
+ return [3
11663
+ /*break*/
11664
+ , 4];
11665
+
11666
+ case 3:
11667
+ cleanUpError_3 = _a.sent();
11668
+ rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_3.message));
11669
+ return [2
11670
+ /*return*/
11671
+ ];
11672
+
11673
+ case 4:
11674
+ return [2
11675
+ /*return*/
11676
+ , rej(err)];
11677
+
11678
+ case 5:
11679
+ return [2
11680
+ /*return*/
11681
+ , res(result)];
11682
+ }
11683
+ });
11684
+ });
11716
11685
  }, {
11717
11686
  bypassCache: true,
11718
11687
  clientMetadata: clientMetadata
@@ -12045,6 +12014,155 @@ function () {
12045
12014
  });
12046
12015
  });
12047
12016
  };
12017
+ /**
12018
+ * Delete the current authenticated user
12019
+ * @return {Promise}
12020
+ **/
12021
+ // TODO: Check return type void
12022
+
12023
+
12024
+ AuthClass.prototype.deleteUser = function () {
12025
+ return __awaiter(this, void 0, void 0, function () {
12026
+ var e_5, isSignedInHostedUI;
12027
+
12028
+ var _this = this;
12029
+
12030
+ return __generator(this, function (_a) {
12031
+ switch (_a.label) {
12032
+ case 0:
12033
+ _a.trys.push([0, 2,, 3]);
12034
+
12035
+ return [4
12036
+ /*yield*/
12037
+ , this._storageSync];
12038
+
12039
+ case 1:
12040
+ _a.sent();
12041
+
12042
+ return [3
12043
+ /*break*/
12044
+ , 3];
12045
+
12046
+ case 2:
12047
+ e_5 = _a.sent();
12048
+ logger.debug('Failed to sync cache info into memory', e_5);
12049
+ throw new Error(e_5);
12050
+
12051
+ case 3:
12052
+ isSignedInHostedUI = this._oAuthHandler && this._storage.getItem('amplify-signin-with-hostedUI') === 'true';
12053
+ return [2
12054
+ /*return*/
12055
+ , new Promise(function (res, rej) {
12056
+ return __awaiter(_this, void 0, void 0, function () {
12057
+ var user_1;
12058
+
12059
+ var _this = this;
12060
+
12061
+ return __generator(this, function (_a) {
12062
+ if (this.userPool) {
12063
+ user_1 = this.userPool.getCurrentUser();
12064
+
12065
+ if (!user_1) {
12066
+ logger.debug('Failed to get user from user pool');
12067
+ return [2
12068
+ /*return*/
12069
+ , rej(new Error('No current user.'))];
12070
+ } else {
12071
+ user_1.getSession(function (err, session) {
12072
+ return __awaiter(_this, void 0, void 0, function () {
12073
+ var cleanUpError_4;
12074
+
12075
+ var _this = this;
12076
+
12077
+ return __generator(this, function (_a) {
12078
+ switch (_a.label) {
12079
+ case 0:
12080
+ if (!err) return [3
12081
+ /*break*/
12082
+ , 5];
12083
+ logger.debug('Failed to get the user session', err);
12084
+ if (!this.isSessionInvalid(err)) return [3
12085
+ /*break*/
12086
+ , 4];
12087
+ _a.label = 1;
12088
+
12089
+ case 1:
12090
+ _a.trys.push([1, 3,, 4]);
12091
+
12092
+ return [4
12093
+ /*yield*/
12094
+ , this.cleanUpInvalidSession(user_1)];
12095
+
12096
+ case 2:
12097
+ _a.sent();
12098
+
12099
+ return [3
12100
+ /*break*/
12101
+ , 4];
12102
+
12103
+ case 3:
12104
+ cleanUpError_4 = _a.sent();
12105
+ rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_4.message));
12106
+ return [2
12107
+ /*return*/
12108
+ ];
12109
+
12110
+ case 4:
12111
+ return [2
12112
+ /*return*/
12113
+ , rej(err)];
12114
+
12115
+ case 5:
12116
+ user_1.deleteUser(function (err, result) {
12117
+ if (err) {
12118
+ rej(err);
12119
+ } else {
12120
+ dispatchAuthEvent('userDeleted', result, 'The authenticated user has been deleted.');
12121
+ user_1.signOut();
12122
+ _this.user = null;
12123
+
12124
+ try {
12125
+ _this.cleanCachedItems(); // clean aws credentials
12126
+
12127
+ } catch (e) {
12128
+ // TODO: change to rejects in refactor
12129
+ logger.debug('failed to clear cached items');
12130
+ }
12131
+
12132
+ if (isSignedInHostedUI) {
12133
+ _this.oAuthSignOutRedirect(res, rej);
12134
+ } else {
12135
+ dispatchAuthEvent('signOut', _this.user, "A user has been signed out");
12136
+ res(result);
12137
+ }
12138
+ }
12139
+ });
12140
+ _a.label = 6;
12141
+
12142
+ case 6:
12143
+ return [2
12144
+ /*return*/
12145
+ ];
12146
+ }
12147
+ });
12148
+ });
12149
+ });
12150
+ }
12151
+ } else {
12152
+ logger.debug('no Congito User pool');
12153
+ rej(new Error('Cognito User pool does not exist'));
12154
+ }
12155
+
12156
+ return [2
12157
+ /*return*/
12158
+ ];
12159
+ });
12160
+ });
12161
+ })];
12162
+ }
12163
+ });
12164
+ });
12165
+ };
12048
12166
  /**
12049
12167
  * Update an authenticated users' attributes
12050
12168
  * @param {CognitoUser} - The currently logged in user object
@@ -12133,6 +12251,93 @@ function () {
12133
12251
  };
12134
12252
  });
12135
12253
  };
12254
+
12255
+ AuthClass.prototype.isErrorWithMessage = function (err) {
12256
+ return _typeof(err) === 'object' && Object.prototype.hasOwnProperty.call(err, 'message');
12257
+ }; // Session revoked by another app
12258
+
12259
+
12260
+ AuthClass.prototype.isTokenRevokedError = function (err) {
12261
+ return this.isErrorWithMessage(err) && err.message === 'Access Token has been revoked';
12262
+ };
12263
+
12264
+ AuthClass.prototype.isRefreshTokenRevokedError = function (err) {
12265
+ return this.isErrorWithMessage(err) && err.message === 'Refresh Token has been revoked';
12266
+ };
12267
+
12268
+ AuthClass.prototype.isUserDisabledError = function (err) {
12269
+ return this.isErrorWithMessage(err) && err.message === 'User is disabled.';
12270
+ };
12271
+
12272
+ AuthClass.prototype.isUserDoesNotExistError = function (err) {
12273
+ return this.isErrorWithMessage(err) && err.message === 'User does not exist.';
12274
+ };
12275
+
12276
+ AuthClass.prototype.isRefreshTokenExpiredError = function (err) {
12277
+ return this.isErrorWithMessage(err) && err.message === 'Refresh Token has expired';
12278
+ };
12279
+
12280
+ AuthClass.prototype.isSignedInHostedUI = function () {
12281
+ return this._oAuthHandler && this._storage.getItem('amplify-signin-with-hostedUI') === 'true';
12282
+ };
12283
+
12284
+ AuthClass.prototype.isSessionInvalid = function (err) {
12285
+ return this.isUserDisabledError(err) || this.isUserDoesNotExistError(err) || this.isTokenRevokedError(err) || this.isRefreshTokenRevokedError(err) || this.isRefreshTokenExpiredError(err);
12286
+ };
12287
+
12288
+ AuthClass.prototype.cleanUpInvalidSession = function (user) {
12289
+ return __awaiter(this, void 0, void 0, function () {
12290
+ var e_6;
12291
+
12292
+ var _this = this;
12293
+
12294
+ return __generator(this, function (_a) {
12295
+ switch (_a.label) {
12296
+ case 0:
12297
+ user.signOut();
12298
+ this.user = null;
12299
+ _a.label = 1;
12300
+
12301
+ case 1:
12302
+ _a.trys.push([1, 3,, 4]);
12303
+
12304
+ return [4
12305
+ /*yield*/
12306
+ , this.cleanCachedItems()];
12307
+
12308
+ case 2:
12309
+ _a.sent(); // clean aws credentials
12310
+
12311
+
12312
+ return [3
12313
+ /*break*/
12314
+ , 4];
12315
+
12316
+ case 3:
12317
+ e_6 = _a.sent();
12318
+ logger.debug('failed to clear cached items');
12319
+ return [3
12320
+ /*break*/
12321
+ , 4];
12322
+
12323
+ case 4:
12324
+ if (this.isSignedInHostedUI()) {
12325
+ return [2
12326
+ /*return*/
12327
+ , new Promise(function (res, rej) {
12328
+ _this.oAuthSignOutRedirect(res, rej);
12329
+ })];
12330
+ } else {
12331
+ dispatchAuthEvent('signOut', this.user, "A user has been signed out");
12332
+ }
12333
+
12334
+ return [2
12335
+ /*return*/
12336
+ ];
12337
+ }
12338
+ });
12339
+ });
12340
+ };
12136
12341
  /**
12137
12342
  * Get current authenticated user
12138
12343
  * @return - A promise resolves to current authenticated CognitoUser if success
@@ -12203,74 +12408,143 @@ function () {
12203
12408
 
12204
12409
  user.getSession(function (err, session) {
12205
12410
  return __awaiter(_this, void 0, void 0, function () {
12206
- var bypassCache, clientMetadata, _a, scope;
12411
+ var cleanUpError_5, bypassCache, clientMetadata, _a, scope;
12207
12412
 
12208
12413
  var _this = this;
12209
12414
 
12210
12415
  return __generator(this, function (_b) {
12211
12416
  switch (_b.label) {
12212
12417
  case 0:
12213
- if (err) {
12214
- logger.debug('Failed to get the user session', err);
12215
- rej(err);
12216
- return [2
12217
- /*return*/
12218
- ];
12219
- }
12418
+ if (!err) return [3
12419
+ /*break*/
12420
+ , 5];
12421
+ logger.debug('Failed to get the user session', err);
12422
+ if (!this.isSessionInvalid(err)) return [3
12423
+ /*break*/
12424
+ , 4];
12425
+ _b.label = 1;
12426
+
12427
+ case 1:
12428
+ _b.trys.push([1, 3,, 4]);
12429
+
12430
+ return [4
12431
+ /*yield*/
12432
+ , this.cleanUpInvalidSession(user)];
12433
+
12434
+ case 2:
12435
+ _b.sent();
12220
12436
 
12437
+ return [3
12438
+ /*break*/
12439
+ , 4];
12440
+
12441
+ case 3:
12442
+ cleanUpError_5 = _b.sent();
12443
+ rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_5.message));
12444
+ return [2
12445
+ /*return*/
12446
+ ];
12447
+
12448
+ case 4:
12449
+ rej(err);
12450
+ return [2
12451
+ /*return*/
12452
+ ];
12453
+
12454
+ case 5:
12221
12455
  bypassCache = params ? params.bypassCache : false;
12222
12456
  if (!bypassCache) return [3
12223
12457
  /*break*/
12224
- , 2];
12458
+ , 7];
12225
12459
  return [4
12226
12460
  /*yield*/
12227
12461
  , this.Credentials.clear()];
12228
12462
 
12229
- case 1:
12463
+ case 6:
12230
12464
  _b.sent();
12231
12465
 
12232
- _b.label = 2;
12466
+ _b.label = 7;
12233
12467
 
12234
- case 2:
12468
+ case 7:
12235
12469
  clientMetadata = this._config.clientMetadata;
12236
12470
  _a = session.getAccessToken().decodePayload().scope, scope = _a === void 0 ? '' : _a;
12237
12471
 
12238
12472
  if (scope.split(' ').includes(USER_ADMIN_SCOPE)) {
12239
12473
  user.getUserData(function (err, data) {
12240
- if (err) {
12241
- logger.debug('getting user data failed', err); // Make sure the user is still valid
12242
-
12243
- if (err.message === 'User is disabled.' || err.message === 'User does not exist.' || err.message === 'Access Token has been revoked' // Session revoked by another app
12244
- ) {
12245
- rej(err);
12246
- } else {
12247
- // the error may also be thrown when lack of permissions to get user info etc
12248
- // in that case we just bypass the error
12249
- res(user);
12250
- }
12251
-
12252
- return;
12253
- }
12254
-
12255
- var preferredMFA = data.PreferredMfaSetting || 'NOMFA';
12256
- var attributeList = [];
12257
-
12258
- for (var i = 0; i < data.UserAttributes.length; i++) {
12259
- var attribute = {
12260
- Name: data.UserAttributes[i].Name,
12261
- Value: data.UserAttributes[i].Value
12262
- };
12263
- var userAttribute = new amazon_cognito_identity_js__WEBPACK_IMPORTED_MODULE_2__["CognitoUserAttribute"](attribute);
12264
- attributeList.push(userAttribute);
12265
- }
12266
-
12267
- var attributes = _this.attributesToObject(attributeList);
12268
-
12269
- Object.assign(user, {
12270
- attributes: attributes,
12271
- preferredMFA: preferredMFA
12474
+ return __awaiter(_this, void 0, void 0, function () {
12475
+ var cleanUpError_6, preferredMFA, attributeList, i, attribute, userAttribute, attributes;
12476
+ return __generator(this, function (_a) {
12477
+ switch (_a.label) {
12478
+ case 0:
12479
+ if (!err) return [3
12480
+ /*break*/
12481
+ , 7];
12482
+ logger.debug('getting user data failed', err);
12483
+ if (!this.isSessionInvalid(err)) return [3
12484
+ /*break*/
12485
+ , 5];
12486
+ _a.label = 1;
12487
+
12488
+ case 1:
12489
+ _a.trys.push([1, 3,, 4]);
12490
+
12491
+ return [4
12492
+ /*yield*/
12493
+ , this.cleanUpInvalidSession(user)];
12494
+
12495
+ case 2:
12496
+ _a.sent();
12497
+
12498
+ return [3
12499
+ /*break*/
12500
+ , 4];
12501
+
12502
+ case 3:
12503
+ cleanUpError_6 = _a.sent();
12504
+ rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_6.message));
12505
+ return [2
12506
+ /*return*/
12507
+ ];
12508
+
12509
+ case 4:
12510
+ rej(err);
12511
+ return [3
12512
+ /*break*/
12513
+ , 6];
12514
+
12515
+ case 5:
12516
+ res(user);
12517
+ _a.label = 6;
12518
+
12519
+ case 6:
12520
+ return [2
12521
+ /*return*/
12522
+ ];
12523
+
12524
+ case 7:
12525
+ preferredMFA = data.PreferredMfaSetting || 'NOMFA';
12526
+ attributeList = [];
12527
+
12528
+ for (i = 0; i < data.UserAttributes.length; i++) {
12529
+ attribute = {
12530
+ Name: data.UserAttributes[i].Name,
12531
+ Value: data.UserAttributes[i].Value
12532
+ };
12533
+ userAttribute = new amazon_cognito_identity_js__WEBPACK_IMPORTED_MODULE_2__["CognitoUserAttribute"](attribute);
12534
+ attributeList.push(userAttribute);
12535
+ }
12536
+
12537
+ attributes = this.attributesToObject(attributeList);
12538
+ Object.assign(user, {
12539
+ attributes: attributes,
12540
+ preferredMFA: preferredMFA
12541
+ });
12542
+ return [2
12543
+ /*return*/
12544
+ , res(user)];
12545
+ }
12546
+ });
12272
12547
  });
12273
- return res(user);
12274
12548
  }, {
12275
12549
  bypassCache: bypassCache,
12276
12550
  clientMetadata: clientMetadata
@@ -12316,7 +12590,7 @@ function () {
12316
12590
 
12317
12591
  AuthClass.prototype.currentAuthenticatedUser = function (params) {
12318
12592
  return __awaiter(this, void 0, void 0, function () {
12319
- var federatedUser, e_5, federatedInfo, user, e_6;
12593
+ var federatedUser, e_7, federatedInfo, user, e_8;
12320
12594
  return __generator(this, function (_a) {
12321
12595
  switch (_a.label) {
12322
12596
  case 0:
@@ -12339,9 +12613,9 @@ function () {
12339
12613
  , 4];
12340
12614
 
12341
12615
  case 3:
12342
- e_5 = _a.sent();
12343
- logger.debug('Failed to sync cache info into memory', e_5);
12344
- throw e_5;
12616
+ e_7 = _a.sent();
12617
+ logger.debug('Failed to sync cache info into memory', e_7);
12618
+ throw e_7;
12345
12619
 
12346
12620
  case 4:
12347
12621
  try {
@@ -12384,13 +12658,13 @@ function () {
12384
12658
  , 9];
12385
12659
 
12386
12660
  case 8:
12387
- e_6 = _a.sent();
12661
+ e_8 = _a.sent();
12388
12662
 
12389
- if (e_6 === 'No userPool') {
12663
+ if (e_8 === 'No userPool') {
12390
12664
  logger.error('Cannot get the current user because the user pool is missing. ' + 'Please make sure the Auth module is configured with a valid Cognito User Pool ID');
12391
12665
  }
12392
12666
 
12393
- logger.debug('The user is not authenticated by the error', e_6);
12667
+ logger.debug('The user is not authenticated by the error', e_8);
12394
12668
  return [2
12395
12669
  /*return*/
12396
12670
  , Promise.reject('The user is not authenticated')];
@@ -12415,7 +12689,7 @@ function () {
12415
12689
  logger.debug('Getting current session'); // Purposely not calling the reject method here because we don't need a console error
12416
12690
 
12417
12691
  if (!this.userPool) {
12418
- return Promise.reject();
12692
+ return this.rejectNoUserPool();
12419
12693
  }
12420
12694
 
12421
12695
  return new Promise(function (res, rej) {
@@ -12443,6 +12717,8 @@ function () {
12443
12717
 
12444
12718
 
12445
12719
  AuthClass.prototype.userSession = function (user) {
12720
+ var _this = this;
12721
+
12446
12722
  if (!user) {
12447
12723
  logger.debug('the user is null');
12448
12724
  return this.rejectAuthError(_types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].NoUserSession);
@@ -12450,18 +12726,59 @@ function () {
12450
12726
 
12451
12727
  var clientMetadata = this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
12452
12728
 
12453
- return new Promise(function (resolve, reject) {
12729
+ return new Promise(function (res, rej) {
12454
12730
  logger.debug('Getting the session from this user:', user);
12455
12731
  user.getSession(function (err, session) {
12456
- if (err) {
12457
- logger.debug('Failed to get the session from user', user);
12458
- reject(err);
12459
- return;
12460
- } else {
12461
- logger.debug('Succeed to get the user session', session);
12462
- resolve(session);
12463
- return;
12464
- }
12732
+ return __awaiter(_this, void 0, void 0, function () {
12733
+ var cleanUpError_7;
12734
+ return __generator(this, function (_a) {
12735
+ switch (_a.label) {
12736
+ case 0:
12737
+ if (!err) return [3
12738
+ /*break*/
12739
+ , 5];
12740
+ logger.debug('Failed to get the session from user', user);
12741
+ if (!this.isSessionInvalid(err)) return [3
12742
+ /*break*/
12743
+ , 4];
12744
+ _a.label = 1;
12745
+
12746
+ case 1:
12747
+ _a.trys.push([1, 3,, 4]);
12748
+
12749
+ return [4
12750
+ /*yield*/
12751
+ , this.cleanUpInvalidSession(user)];
12752
+
12753
+ case 2:
12754
+ _a.sent();
12755
+
12756
+ return [3
12757
+ /*break*/
12758
+ , 4];
12759
+
12760
+ case 3:
12761
+ cleanUpError_7 = _a.sent();
12762
+ rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_7.message));
12763
+ return [2
12764
+ /*return*/
12765
+ ];
12766
+
12767
+ case 4:
12768
+ rej(err);
12769
+ return [2
12770
+ /*return*/
12771
+ ];
12772
+
12773
+ case 5:
12774
+ logger.debug('Succeed to get the user session', session);
12775
+ res(session);
12776
+ return [2
12777
+ /*return*/
12778
+ ];
12779
+ }
12780
+ });
12781
+ });
12465
12782
  }, {
12466
12783
  clientMetadata: clientMetadata
12467
12784
  });
@@ -12475,7 +12792,7 @@ function () {
12475
12792
 
12476
12793
  AuthClass.prototype.currentUserCredentials = function () {
12477
12794
  return __awaiter(this, void 0, void 0, function () {
12478
- var e_7, federatedInfo;
12795
+ var e_9, federatedInfo;
12479
12796
 
12480
12797
  var _this = this;
12481
12798
 
@@ -12500,9 +12817,9 @@ function () {
12500
12817
  , 4];
12501
12818
 
12502
12819
  case 3:
12503
- e_7 = _a.sent();
12504
- logger.debug('Failed to sync cache info into memory', e_7);
12505
- throw e_7;
12820
+ e_9 = _a.sent();
12821
+ logger.debug('Failed to sync cache info into memory', e_9);
12822
+ throw e_9;
12506
12823
 
12507
12824
  case 4:
12508
12825
  federatedInfo = null;
@@ -12524,8 +12841,8 @@ function () {
12524
12841
  , this.currentSession().then(function (session) {
12525
12842
  logger.debug('getting session success', session);
12526
12843
  return _this.Credentials.set(session, 'session');
12527
- })["catch"](function (error) {
12528
- logger.debug('getting session failed', error);
12844
+ })["catch"](function () {
12845
+ logger.debug('getting guest credentials');
12529
12846
  return _this.Credentials.set(null, 'guest');
12530
12847
  })];
12531
12848
  }
@@ -12617,7 +12934,7 @@ function () {
12617
12934
 
12618
12935
  AuthClass.prototype.cognitoIdentitySignOut = function (opts, user) {
12619
12936
  return __awaiter(this, void 0, void 0, function () {
12620
- var e_8, isSignedInHostedUI;
12937
+ var e_10, isSignedInHostedUI;
12621
12938
 
12622
12939
  var _this = this;
12623
12940
 
@@ -12638,9 +12955,9 @@ function () {
12638
12955
  , 3];
12639
12956
 
12640
12957
  case 2:
12641
- e_8 = _a.sent();
12642
- logger.debug('Failed to sync cache info into memory', e_8);
12643
- throw e_8;
12958
+ e_10 = _a.sent();
12959
+ logger.debug('Failed to sync cache info into memory', e_10);
12960
+ throw e_10;
12644
12961
 
12645
12962
  case 3:
12646
12963
  isSignedInHostedUI = this._oAuthHandler && this._storage.getItem('amplify-signin-with-hostedUI') === 'true';
@@ -12654,25 +12971,70 @@ function () {
12654
12971
  var clientMetadata = _this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
12655
12972
 
12656
12973
  user.getSession(function (err, result) {
12657
- if (err) {
12658
- logger.debug('failed to get the user session', err);
12659
- return rej(err);
12660
- }
12974
+ return __awaiter(_this, void 0, void 0, function () {
12975
+ var cleanUpError_8;
12661
12976
 
12662
- user.globalSignOut({
12663
- onSuccess: function onSuccess(data) {
12664
- logger.debug('global sign out success');
12977
+ var _this = this;
12978
+
12979
+ return __generator(this, function (_a) {
12980
+ switch (_a.label) {
12981
+ case 0:
12982
+ if (!err) return [3
12983
+ /*break*/
12984
+ , 5];
12985
+ logger.debug('failed to get the user session', err);
12986
+ if (!this.isSessionInvalid(err)) return [3
12987
+ /*break*/
12988
+ , 4];
12989
+ _a.label = 1;
12990
+
12991
+ case 1:
12992
+ _a.trys.push([1, 3,, 4]);
12665
12993
 
12666
- if (isSignedInHostedUI) {
12667
- _this.oAuthSignOutRedirect(res, rej);
12668
- } else {
12669
- return res();
12994
+ return [4
12995
+ /*yield*/
12996
+ , this.cleanUpInvalidSession(user)];
12997
+
12998
+ case 2:
12999
+ _a.sent();
13000
+
13001
+ return [3
13002
+ /*break*/
13003
+ , 4];
13004
+
13005
+ case 3:
13006
+ cleanUpError_8 = _a.sent();
13007
+ rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_8.message));
13008
+ return [2
13009
+ /*return*/
13010
+ ];
13011
+
13012
+ case 4:
13013
+ return [2
13014
+ /*return*/
13015
+ , rej(err)];
13016
+
13017
+ case 5:
13018
+ user.globalSignOut({
13019
+ onSuccess: function onSuccess(data) {
13020
+ logger.debug('global sign out success');
13021
+
13022
+ if (isSignedInHostedUI) {
13023
+ _this.oAuthSignOutRedirect(res, rej);
13024
+ } else {
13025
+ return res();
13026
+ }
13027
+ },
13028
+ onFailure: function onFailure(err) {
13029
+ logger.debug('global sign out failed', err);
13030
+ return rej(err);
13031
+ }
13032
+ });
13033
+ return [2
13034
+ /*return*/
13035
+ ];
12670
13036
  }
12671
- },
12672
- onFailure: function onFailure(err) {
12673
- logger.debug('global sign out failed', err);
12674
- return rej(err);
12675
- }
13037
+ });
12676
13038
  });
12677
13039
  }, {
12678
13040
  clientMetadata: clientMetadata
@@ -12694,7 +13056,7 @@ function () {
12694
13056
  };
12695
13057
 
12696
13058
  AuthClass.prototype.oAuthSignOutRedirect = function (resolve, reject) {
12697
- var isBrowser = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["JS"].browserOrNode().isBrowser;
13059
+ var isBrowser = Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["browserOrNode"])().isBrowser;
12698
13060
 
12699
13061
  if (isBrowser) {
12700
13062
  this.oAuthSignOutRedirectOrReject(reject);
@@ -12715,7 +13077,7 @@ function () {
12715
13077
 
12716
13078
 
12717
13079
  setTimeout(function () {
12718
- return reject('Signout timeout fail');
13080
+ return reject(Error('Signout timeout fail'));
12719
13081
  }, 3000);
12720
13082
  };
12721
13083
  /**
@@ -12727,7 +13089,7 @@ function () {
12727
13089
 
12728
13090
  AuthClass.prototype.signOut = function (opts) {
12729
13091
  return __awaiter(this, void 0, void 0, function () {
12730
- var e_9, user;
13092
+ var e_11, user;
12731
13093
  return __generator(this, function (_a) {
12732
13094
  switch (_a.label) {
12733
13095
  case 0:
@@ -12745,7 +13107,7 @@ function () {
12745
13107
  , 3];
12746
13108
 
12747
13109
  case 2:
12748
- e_9 = _a.sent();
13110
+ e_11 = _a.sent();
12749
13111
  logger.debug('failed to clear cached items');
12750
13112
  return [3
12751
13113
  /*break*/
@@ -12780,7 +13142,7 @@ function () {
12780
13142
  , 8];
12781
13143
 
12782
13144
  case 7:
12783
- logger.debug('no Congito User pool');
13145
+ logger.debug('no Cognito User pool');
12784
13146
  _a.label = 8;
12785
13147
 
12786
13148
  case 8:
@@ -12946,7 +13308,7 @@ function () {
12946
13308
 
12947
13309
  AuthClass.prototype.currentUserInfo = function () {
12948
13310
  return __awaiter(this, void 0, void 0, function () {
12949
- var source, user, attributes, userAttrs, credentials, e_10, info, err_1, user;
13311
+ var source, user, attributes, userAttrs, credentials, e_12, info, err_1, user;
12950
13312
  return __generator(this, function (_a) {
12951
13313
  switch (_a.label) {
12952
13314
  case 0:
@@ -12998,8 +13360,8 @@ function () {
12998
13360
  , 7];
12999
13361
 
13000
13362
  case 6:
13001
- e_10 = _a.sent();
13002
- logger.debug('Failed to retrieve credentials while getting current user info', e_10);
13363
+ e_12 = _a.sent();
13364
+ logger.debug('Failed to retrieve credentials while getting current user info', e_12);
13003
13365
  return [3
13004
13366
  /*break*/
13005
13367
  , 7];
@@ -13152,7 +13514,7 @@ function () {
13152
13514
  dispatchAuthEvent('parsingCallbackUrl', {
13153
13515
  url: URL
13154
13516
  }, "The callback url is being parsed");
13155
- currentUrl = URL || (_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["JS"].browserOrNode().isBrowser ? window.location.href : '');
13517
+ currentUrl = URL || (Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["browserOrNode"])().isBrowser ? window.location.href : '');
13156
13518
  hasCodeOrError = !!(Object(url__WEBPACK_IMPORTED_MODULE_3__["parse"])(currentUrl).query || '').split('&').map(function (entry) {
13157
13519
  return entry.split('=');
13158
13520
  }).find(function (_a) {
@@ -14399,7 +14761,7 @@ var AuthErrorStrings;
14399
14761
  /*!**************************!*\
14400
14762
  !*** ./lib-esm/index.js ***!
14401
14763
  \**************************/
14402
- /*! exports provided: default, Auth, CognitoUser, CookieStorage, CognitoHostedUIIdentityProvider, appendToCognitoUserAgent, AuthErrorStrings */
14764
+ /*! exports provided: default, Auth, CognitoUser, CookieStorage, CognitoHostedUIIdentityProvider, appendToCognitoUserAgent, AuthErrorStrings, GRAPHQL_AUTH_MODE */
14403
14765
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
14404
14766
 
14405
14767
  "use strict";
@@ -14410,6 +14772,8 @@ __webpack_require__.r(__webpack_exports__);
14410
14772
  /* harmony import */ var _types_Auth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./types/Auth */ "./lib-esm/types/Auth.js");
14411
14773
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CognitoHostedUIIdentityProvider", function() { return _types_Auth__WEBPACK_IMPORTED_MODULE_1__["CognitoHostedUIIdentityProvider"]; });
14412
14774
 
14775
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GRAPHQL_AUTH_MODE", function() { return _types_Auth__WEBPACK_IMPORTED_MODULE_1__["GRAPHQL_AUTH_MODE"]; });
14776
+
14413
14777
  /* harmony import */ var amazon_cognito_identity_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! amazon-cognito-identity-js */ "../amazon-cognito-identity-js/es/index.js");
14414
14778
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CognitoUser", function() { return amazon_cognito_identity_js__WEBPACK_IMPORTED_MODULE_2__["CognitoUser"]; });
14415
14779
 
@@ -14449,7 +14813,7 @@ __webpack_require__.r(__webpack_exports__);
14449
14813
  /*!*******************************!*\
14450
14814
  !*** ./lib-esm/types/Auth.js ***!
14451
14815
  \*******************************/
14452
- /*! exports provided: CognitoHostedUIIdentityProvider, isFederatedSignInOptions, isFederatedSignInOptionsCustom, hasCustomState, isCognitoHostedOpts, AuthErrorTypes, isUsernamePasswordOpts */
14816
+ /*! exports provided: CognitoHostedUIIdentityProvider, isFederatedSignInOptions, isFederatedSignInOptionsCustom, hasCustomState, isCognitoHostedOpts, AuthErrorTypes, isUsernamePasswordOpts, GRAPHQL_AUTH_MODE */
14453
14817
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
14454
14818
 
14455
14819
  "use strict";
@@ -14461,6 +14825,7 @@ __webpack_require__.r(__webpack_exports__);
14461
14825
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isCognitoHostedOpts", function() { return isCognitoHostedOpts; });
14462
14826
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AuthErrorTypes", function() { return AuthErrorTypes; });
14463
14827
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isUsernamePasswordOpts", function() { return isUsernamePasswordOpts; });
14828
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GRAPHQL_AUTH_MODE", function() { return GRAPHQL_AUTH_MODE; });
14464
14829
  /*
14465
14830
  * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14466
14831
  *
@@ -14526,6 +14891,15 @@ var AuthErrorTypes;
14526
14891
  function isUsernamePasswordOpts(obj) {
14527
14892
  return !!obj.username;
14528
14893
  }
14894
+ var GRAPHQL_AUTH_MODE;
14895
+
14896
+ (function (GRAPHQL_AUTH_MODE) {
14897
+ GRAPHQL_AUTH_MODE["API_KEY"] = "API_KEY";
14898
+ GRAPHQL_AUTH_MODE["AWS_IAM"] = "AWS_IAM";
14899
+ GRAPHQL_AUTH_MODE["OPENID_CONNECT"] = "OPENID_CONNECT";
14900
+ GRAPHQL_AUTH_MODE["AMAZON_COGNITO_USER_POOLS"] = "AMAZON_COGNITO_USER_POOLS";
14901
+ GRAPHQL_AUTH_MODE["AWS_LAMBDA"] = "AWS_LAMBDA";
14902
+ })(GRAPHQL_AUTH_MODE || (GRAPHQL_AUTH_MODE = {}));
14529
14903
 
14530
14904
  /***/ }),
14531
14905
 
@@ -14533,7 +14907,7 @@ function isUsernamePasswordOpts(obj) {
14533
14907
  /*!********************************!*\
14534
14908
  !*** ./lib-esm/types/index.js ***!
14535
14909
  \********************************/
14536
- /*! exports provided: CognitoHostedUIIdentityProvider, isFederatedSignInOptions, isFederatedSignInOptionsCustom, hasCustomState, isCognitoHostedOpts, AuthErrorTypes, isUsernamePasswordOpts */
14910
+ /*! exports provided: CognitoHostedUIIdentityProvider, isFederatedSignInOptions, isFederatedSignInOptionsCustom, hasCustomState, isCognitoHostedOpts, AuthErrorTypes, isUsernamePasswordOpts, GRAPHQL_AUTH_MODE */
14537
14911
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
14538
14912
 
14539
14913
  "use strict";
@@ -14553,6 +14927,8 @@ __webpack_require__.r(__webpack_exports__);
14553
14927
 
14554
14928
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "isUsernamePasswordOpts", function() { return _Auth__WEBPACK_IMPORTED_MODULE_0__["isUsernamePasswordOpts"]; });
14555
14929
 
14930
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GRAPHQL_AUTH_MODE", function() { return _Auth__WEBPACK_IMPORTED_MODULE_0__["GRAPHQL_AUTH_MODE"]; });
14931
+
14556
14932
  /*
14557
14933
  * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14558
14934
  *
@@ -14594,12 +14970,12 @@ __webpack_require__.r(__webpack_exports__);
14594
14970
  */
14595
14971
 
14596
14972
  /* harmony default export */ __webpack_exports__["default"] = (function (callback) {
14597
- if (_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["JS"].browserOrNode().isBrowser && window.location) {
14973
+ if (Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["browserOrNode"])().isBrowser && window.location) {
14598
14974
  var url = window.location.href;
14599
14975
  callback({
14600
14976
  url: url
14601
14977
  });
14602
- } else if (_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["JS"].browserOrNode().isNode) {
14978
+ } else if (Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["browserOrNode"])().isNode) {
14603
14979
  // continue building on ssr
14604
14980
  (function () {}); // noop
14605
14981