@aws-amplify/datastore 3.12.1 → 3.12.2-auto-sign-in.10

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.
@@ -60708,6 +60708,7 @@ var dispatchAuthEvent = function dispatchAuthEvent(event, data, message) {
60708
60708
 
60709
60709
 
60710
60710
  var MAX_DEVICES = 60;
60711
+ var MAX_AUTOSIGNIN_POLLING_MS = 3 * 60 * 1000;
60711
60712
  /**
60712
60713
  * Provide authentication steps
60713
60714
  */
@@ -60725,6 +60726,7 @@ function () {
60725
60726
  this.userPool = null;
60726
60727
  this.user = null;
60727
60728
  this.oAuthFlowInProgress = false;
60729
+ this.autoSignInInitiated = false;
60728
60730
  this.Credentials = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Credentials"];
60729
60731
 
60730
60732
  this.wrapRefreshSessionCallback = function (callback) {
@@ -60870,6 +60872,17 @@ function () {
60870
60872
  }
60871
60873
 
60872
60874
  dispatchAuthEvent('configured', null, "The Auth category has been configured successfully");
60875
+
60876
+ if (!this.autoSignInInitiated && typeof this._storage['getItem'] === 'function') {
60877
+ var pollingInitiated = this.isTrueStorageValue('amplify-polling-started');
60878
+
60879
+ if (pollingInitiated) {
60880
+ dispatchAuthEvent('autoSignIn_failure', null, _types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].AutoSignInError);
60881
+ }
60882
+
60883
+ this._storage.removeItem('amplify-polling-started');
60884
+ }
60885
+
60873
60886
  return this._config;
60874
60887
  };
60875
60888
  /**
@@ -60889,6 +60902,8 @@ function () {
60889
60902
  restOfAttrs[_i - 1] = arguments[_i];
60890
60903
  }
60891
60904
 
60905
+ var _a, _b, _c;
60906
+
60892
60907
  if (!this.userPool) {
60893
60908
  return this.rejectNoUserPool();
60894
60909
  }
@@ -60898,6 +60913,11 @@ function () {
60898
60913
  var attributes = [];
60899
60914
  var validationData = null;
60900
60915
  var clientMetadata;
60916
+ var autoSignIn = {
60917
+ enabled: false
60918
+ };
60919
+ var autoSignInValidationData = {};
60920
+ var autoSignInClientMetaData = {};
60901
60921
 
60902
60922
  if (params && typeof params === 'string') {
60903
60923
  username = params;
@@ -60944,6 +60964,17 @@ function () {
60944
60964
  }));
60945
60965
  });
60946
60966
  }
60967
+
60968
+ autoSignIn = (_a = params.autoSignIn) !== null && _a !== void 0 ? _a : {
60969
+ enabled: false
60970
+ };
60971
+
60972
+ if (autoSignIn.enabled) {
60973
+ this._storage.setItem('amplify-auto-sign-in', true);
60974
+
60975
+ autoSignInValidationData = (_b = autoSignIn.validationData) !== null && _b !== void 0 ? _b : {};
60976
+ autoSignInClientMetaData = (_c = autoSignIn.clientMetaData) !== null && _c !== void 0 ? _c : {};
60977
+ }
60947
60978
  } else {
60948
60979
  return this.rejectAuthError(_types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].SignUpError);
60949
60980
  }
@@ -60965,11 +60996,122 @@ function () {
60965
60996
  reject(err);
60966
60997
  } else {
60967
60998
  dispatchAuthEvent('signUp', data, username + " has signed up successfully");
60999
+
61000
+ if (autoSignIn.enabled) {
61001
+ _this.handleAutoSignIn(username, password, autoSignInValidationData, autoSignInClientMetaData, data);
61002
+ }
61003
+
60968
61004
  resolve(data);
60969
61005
  }
60970
61006
  }, clientMetadata);
60971
61007
  });
60972
61008
  };
61009
+
61010
+ AuthClass.prototype.handleAutoSignIn = function (username, password, validationData, clientMetadata, data) {
61011
+ this.autoSignInInitiated = true;
61012
+ var authDetails = new amazon_cognito_identity_js__WEBPACK_IMPORTED_MODULE_2__["AuthenticationDetails"]({
61013
+ Username: username,
61014
+ Password: password,
61015
+ ValidationData: validationData,
61016
+ ClientMetadata: clientMetadata
61017
+ });
61018
+
61019
+ if (data.userConfirmed) {
61020
+ this.signInAfterUserConfirmed(authDetails);
61021
+ } else if (this._config.signUpVerificationMethod === 'link') {
61022
+ this.handleLinkAutoSignIn(authDetails);
61023
+ } else {
61024
+ this.handleCodeAutoSignIn(authDetails);
61025
+ }
61026
+ };
61027
+
61028
+ AuthClass.prototype.handleCodeAutoSignIn = function (authDetails) {
61029
+ var _this = this;
61030
+
61031
+ var listenEvent = function listenEvent(_a) {
61032
+ var payload = _a.payload;
61033
+
61034
+ if (payload.event === 'confirmSignUp') {
61035
+ _this.signInAfterUserConfirmed(authDetails, listenEvent);
61036
+ }
61037
+ };
61038
+
61039
+ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Hub"].listen('auth', listenEvent);
61040
+ };
61041
+
61042
+ AuthClass.prototype.handleLinkAutoSignIn = function (authDetails) {
61043
+ var _this = this;
61044
+
61045
+ this._storage.setItem('amplify-polling-started', true);
61046
+
61047
+ var start = Date.now();
61048
+ var autoSignInPollingIntervalId = setInterval(function () {
61049
+ if (Date.now() - start > MAX_AUTOSIGNIN_POLLING_MS) {
61050
+ clearInterval(autoSignInPollingIntervalId);
61051
+ dispatchAuthEvent('autoSignIn_failure', null, 'Please confirm your account and use your credentials to sign in.');
61052
+ } else {
61053
+ _this.signInAfterUserConfirmed(authDetails, null, autoSignInPollingIntervalId);
61054
+ }
61055
+ }, 5000);
61056
+ };
61057
+
61058
+ AuthClass.prototype.signInAfterUserConfirmed = function (authDetails, listenEvent, autoSignInPollingIntervalId) {
61059
+ return __awaiter(this, void 0, void 0, function () {
61060
+ var user, error_1;
61061
+
61062
+ var _this = this;
61063
+
61064
+ return __generator(this, function (_a) {
61065
+ switch (_a.label) {
61066
+ case 0:
61067
+ user = this.createCognitoUser(authDetails.getUsername());
61068
+ _a.label = 1;
61069
+
61070
+ case 1:
61071
+ _a.trys.push([1, 3,, 4]);
61072
+
61073
+ return [4
61074
+ /*yield*/
61075
+ , user.authenticateUser(authDetails, this.authCallbacks(user, function (value) {
61076
+ dispatchAuthEvent('autoSignIn', value, authDetails.getUsername() + " has signed in successfully");
61077
+
61078
+ if (listenEvent) {
61079
+ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Hub"].remove('auth', listenEvent);
61080
+ }
61081
+
61082
+ if (autoSignInPollingIntervalId) {
61083
+ clearInterval(autoSignInPollingIntervalId);
61084
+
61085
+ _this._storage.removeItem('amplify-polling-started');
61086
+ }
61087
+
61088
+ _this._storage.removeItem('amplify-auto-sign-in');
61089
+ }, function (error) {
61090
+ logger.error(error);
61091
+ }))];
61092
+
61093
+ case 2:
61094
+ _a.sent();
61095
+
61096
+ return [3
61097
+ /*break*/
61098
+ , 4];
61099
+
61100
+ case 3:
61101
+ error_1 = _a.sent();
61102
+ logger.error(error_1);
61103
+ return [3
61104
+ /*break*/
61105
+ , 4];
61106
+
61107
+ case 4:
61108
+ return [2
61109
+ /*return*/
61110
+ ];
61111
+ }
61112
+ });
61113
+ });
61114
+ };
60973
61115
  /**
60974
61116
  * Send the verification code to confirm sign up
60975
61117
  * @param {String} username - The username to be confirmed
@@ -60980,6 +61122,8 @@ function () {
60980
61122
 
60981
61123
 
60982
61124
  AuthClass.prototype.confirmSignUp = function (username, code, options) {
61125
+ var _this = this;
61126
+
60983
61127
  if (!this.userPool) {
60984
61128
  return this.rejectNoUserPool();
60985
61129
  }
@@ -61007,11 +61151,25 @@ function () {
61007
61151
  if (err) {
61008
61152
  reject(err);
61009
61153
  } else {
61154
+ dispatchAuthEvent('confirmSignUp', data, username + " has been confirmed successfully");
61155
+
61156
+ var autoSignIn = _this.isTrueStorageValue('amplify-auto-sign-in');
61157
+
61158
+ if (autoSignIn && !_this.autoSignInInitiated) {
61159
+ dispatchAuthEvent('autoSignIn_failure', null, _types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].AutoSignInError);
61160
+ }
61161
+
61010
61162
  resolve(data);
61011
61163
  }
61012
61164
  }, clientMetadata);
61013
61165
  });
61014
61166
  };
61167
+
61168
+ AuthClass.prototype.isTrueStorageValue = function (value) {
61169
+ var item = this._storage.getItem(value);
61170
+
61171
+ return item ? item === 'true' : false;
61172
+ };
61015
61173
  /**
61016
61174
  * Resend the verification code
61017
61175
  * @param {String} username - The username to be confirmed
@@ -63054,7 +63212,7 @@ function () {
63054
63212
  };
63055
63213
 
63056
63214
  AuthClass.prototype.oAuthSignOutRedirect = function (resolve, reject) {
63057
- var isBrowser = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["JS"].browserOrNode().isBrowser;
63215
+ var isBrowser = Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["browserOrNode"])().isBrowser;
63058
63216
 
63059
63217
  if (isBrowser) {
63060
63218
  this.oAuthSignOutRedirectOrReject(reject);
@@ -63512,7 +63670,7 @@ function () {
63512
63670
  dispatchAuthEvent('parsingCallbackUrl', {
63513
63671
  url: URL
63514
63672
  }, "The callback url is being parsed");
63515
- currentUrl = URL || (_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["JS"].browserOrNode().isBrowser ? window.location.href : '');
63673
+ currentUrl = URL || (Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["browserOrNode"])().isBrowser ? window.location.href : '');
63516
63674
  hasCodeOrError = !!(Object(url__WEBPACK_IMPORTED_MODULE_3__["parse"])(currentUrl).query || '').split('&').map(function (entry) {
63517
63675
  return entry.split('=');
63518
63676
  }).find(function (_a) {
@@ -63709,7 +63867,7 @@ function () {
63709
63867
 
63710
63868
  AuthClass.prototype.rememberDevice = function () {
63711
63869
  return __awaiter(this, void 0, void 0, function () {
63712
- var currUser, error_1;
63870
+ var currUser, error_2;
63713
63871
  return __generator(this, function (_a) {
63714
63872
  switch (_a.label) {
63715
63873
  case 0:
@@ -63726,8 +63884,8 @@ function () {
63726
63884
  , 3];
63727
63885
 
63728
63886
  case 2:
63729
- error_1 = _a.sent();
63730
- logger.debug('The user is not authenticated by the error', error_1);
63887
+ error_2 = _a.sent();
63888
+ logger.debug('The user is not authenticated by the error', error_2);
63731
63889
  return [2
63732
63890
  /*return*/
63733
63891
  , Promise.reject('The user is not authenticated')];
@@ -63759,7 +63917,7 @@ function () {
63759
63917
 
63760
63918
  AuthClass.prototype.forgetDevice = function () {
63761
63919
  return __awaiter(this, void 0, void 0, function () {
63762
- var currUser, error_2;
63920
+ var currUser, error_3;
63763
63921
  return __generator(this, function (_a) {
63764
63922
  switch (_a.label) {
63765
63923
  case 0:
@@ -63776,8 +63934,8 @@ function () {
63776
63934
  , 3];
63777
63935
 
63778
63936
  case 2:
63779
- error_2 = _a.sent();
63780
- logger.debug('The user is not authenticated by the error', error_2);
63937
+ error_3 = _a.sent();
63938
+ logger.debug('The user is not authenticated by the error', error_3);
63781
63939
  return [2
63782
63940
  /*return*/
63783
63941
  , Promise.reject('The user is not authenticated')];
@@ -63809,7 +63967,7 @@ function () {
63809
63967
 
63810
63968
  AuthClass.prototype.fetchDevices = function () {
63811
63969
  return __awaiter(this, void 0, void 0, function () {
63812
- var currUser, error_3;
63970
+ var currUser, error_4;
63813
63971
  return __generator(this, function (_a) {
63814
63972
  switch (_a.label) {
63815
63973
  case 0:
@@ -63826,8 +63984,8 @@ function () {
63826
63984
  , 3];
63827
63985
 
63828
63986
  case 2:
63829
- error_3 = _a.sent();
63830
- logger.debug('The user is not authenticated by the error', error_3);
63987
+ error_4 = _a.sent();
63988
+ logger.debug('The user is not authenticated by the error', error_4);
63831
63989
  throw new Error('The user is not authenticated');
63832
63990
 
63833
63991
  case 3:
@@ -64023,6 +64181,9 @@ var authErrorMessages = {
64023
64181
  networkError: {
64024
64182
  message: _common_AuthErrorStrings__WEBPACK_IMPORTED_MODULE_1__["AuthErrorStrings"].NETWORK_ERROR
64025
64183
  },
64184
+ autoSignInError: {
64185
+ message: _common_AuthErrorStrings__WEBPACK_IMPORTED_MODULE_1__["AuthErrorStrings"].AUTOSIGNIN_ERROR
64186
+ },
64026
64187
  "default": {
64027
64188
  message: _common_AuthErrorStrings__WEBPACK_IMPORTED_MODULE_1__["AuthErrorStrings"].DEFAULT_MSG
64028
64189
  }
@@ -64749,6 +64910,7 @@ var AuthErrorStrings;
64749
64910
  AuthErrorStrings["NO_USER_SESSION"] = "Failed to get the session because the user is empty";
64750
64911
  AuthErrorStrings["NETWORK_ERROR"] = "Network Error";
64751
64912
  AuthErrorStrings["DEVICE_CONFIG"] = "Device tracking has not been configured in this User Pool";
64913
+ AuthErrorStrings["AUTOSIGNIN_ERROR"] = "Please use your credentials to sign in";
64752
64914
  })(AuthErrorStrings || (AuthErrorStrings = {}));
64753
64915
 
64754
64916
  /***/ }),
@@ -64882,6 +65044,7 @@ var AuthErrorTypes;
64882
65044
  AuthErrorTypes["Default"] = "default";
64883
65045
  AuthErrorTypes["DeviceConfig"] = "deviceConfig";
64884
65046
  AuthErrorTypes["NetworkError"] = "networkError";
65047
+ AuthErrorTypes["AutoSignInError"] = "autoSignInError";
64885
65048
  })(AuthErrorTypes || (AuthErrorTypes = {}));
64886
65049
 
64887
65050
  function isUsernamePasswordOpts(obj) {
@@ -64965,12 +65128,12 @@ __webpack_require__.r(__webpack_exports__);
64965
65128
  */
64966
65129
 
64967
65130
  /* harmony default export */ __webpack_exports__["default"] = (function (callback) {
64968
- if (_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["JS"].browserOrNode().isBrowser && window.location) {
65131
+ if (Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["browserOrNode"])().isBrowser && window.location) {
64969
65132
  var url = window.location.href;
64970
65133
  callback({
64971
65134
  url: url
64972
65135
  });
64973
- } else if (_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["JS"].browserOrNode().isNode) {
65136
+ } else if (Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["browserOrNode"])().isNode) {
64974
65137
  // continue building on ssr
64975
65138
  (function () {}); // noop
64976
65139
 
@@ -71107,7 +71270,8 @@ var parseMobileHubConfig = function parseMobileHubConfig(config) {
71107
71270
  region: config['aws_cognito_region'],
71108
71271
  identityPoolId: config['aws_cognito_identity_pool_id'],
71109
71272
  identityPoolRegion: config['aws_cognito_region'],
71110
- mandatorySignIn: config['aws_mandatory_sign_in'] === 'enable'
71273
+ mandatorySignIn: config['aws_mandatory_sign_in'] === 'enable',
71274
+ signUpVerificationMethod: config['aws_cognito_sign_up_verification_method'] || 'code'
71111
71275
  };
71112
71276
  } // Storage
71113
71277
 
@@ -71245,7 +71409,7 @@ var getAmplifyUserAgent = function getAmplifyUserAgent() {
71245
71409
  __webpack_require__.r(__webpack_exports__);
71246
71410
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "version", function() { return version; });
71247
71411
  // generated by genversion
71248
- var version = '4.5.7';
71412
+ var version = '4.5.8';
71249
71413
 
71250
71414
  /***/ }),
71251
71415
 
@@ -94264,6 +94428,32 @@ function () {
94264
94428
  _a = subscriptionError.error, _b = __read((_a === void 0 ? {
94265
94429
  errors: []
94266
94430
  } : _a).errors, 1), _c = _b[0], _d = (_c === void 0 ? {} : _c).message, message = _d === void 0 ? '' : _d;
94431
+
94432
+ if (message.includes(_aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_4__["CONTROL_MSG"].REALTIME_SUBSCRIPTION_INIT_ERROR) || message.includes(_aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_4__["CONTROL_MSG"].CONNECTION_FAILED)) {
94433
+ // Unsubscribe and clear subscription array for model/operation
94434
+ subscriptions[modelDefinition.name][transformerMutationType].forEach(function (subscription) {
94435
+ return subscription.unsubscribe();
94436
+ });
94437
+ subscriptions[modelDefinition.name][transformerMutationType] = [];
94438
+ operationAuthModeAttempts[operation]++;
94439
+
94440
+ if (operationAuthModeAttempts[operation] >= readAuthModes.length) {
94441
+ // last auth mode retry. Continue with error
94442
+ logger.debug(operation + " subscription failed with authMode: " + readAuthModes[operationAuthModeAttempts[operation] - 1]);
94443
+ } else {
94444
+ // retry with different auth mode. Do not trigger
94445
+ // observer error or error handler
94446
+ logger.debug(operation + " subscription failed with authMode: " + readAuthModes[operationAuthModeAttempts[operation] - 1] + ". Retrying with authMode: " + readAuthModes[operationAuthModeAttempts[operation]]);
94447
+
94448
+ _authModeRetry(operation);
94449
+
94450
+ return [2
94451
+ /*return*/
94452
+ ];
94453
+ }
94454
+ }
94455
+
94456
+ logger.warn('subscriptionError', message);
94267
94457
  _e.label = 1;
94268
94458
 
94269
94459
  case 1:
@@ -94292,39 +94482,12 @@ function () {
94292
94482
 
94293
94483
  case 3:
94294
94484
  e_1 = _e.sent();
94295
- logger.error('Sync error handler failed with:', e_1);
94485
+ logger.error('Subscription error handler failed with:', e_1);
94296
94486
  return [3
94297
94487
  /*break*/
94298
94488
  , 4];
94299
94489
 
94300
94490
  case 4:
94301
- if (message.includes(_aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_4__["CONTROL_MSG"].REALTIME_SUBSCRIPTION_INIT_ERROR) || message.includes(_aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_4__["CONTROL_MSG"].CONNECTION_FAILED)) {
94302
- // Unsubscribe and clear subscription array for model/operation
94303
- subscriptions[modelDefinition.name][transformerMutationType].forEach(function (subscription) {
94304
- return subscription.unsubscribe();
94305
- });
94306
- subscriptions[modelDefinition.name][transformerMutationType] = [];
94307
- operationAuthModeAttempts[operation]++;
94308
-
94309
- if (operationAuthModeAttempts[operation] >= readAuthModes.length) {
94310
- logger.debug(operation + " subscription failed with authMode: " + readAuthModes[operationAuthModeAttempts[operation] - 1]);
94311
- logger.warn('subscriptionError', message);
94312
- return [2
94313
- /*return*/
94314
- ];
94315
- } else {
94316
- logger.debug(operation + " subscription failed with authMode: " + readAuthModes[operationAuthModeAttempts[operation] - 1] + ". Retrying with authMode: " + readAuthModes[operationAuthModeAttempts[operation]]);
94317
-
94318
- _authModeRetry(operation);
94319
-
94320
- return [2
94321
- /*return*/
94322
- ];
94323
- }
94324
- }
94325
-
94326
- logger.warn('subscriptionError', message);
94327
-
94328
94491
  if (typeof subscriptionReadyCallback === 'function') {
94329
94492
  subscriptionReadyCallback();
94330
94493
  }