@aws-amplify/auth 4.5.11-unstable.2 → 4.5.11-unstable.3
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.
- package/dist/aws-amplify-auth.js +180 -9
- package/dist/aws-amplify-auth.js.map +1 -1
- package/dist/aws-amplify-auth.min.js +8 -8
- package/dist/aws-amplify-auth.min.js.map +1 -1
- package/lib/Auth.d.ts +6 -0
- package/lib/Auth.js +124 -9
- package/lib/Auth.js.map +1 -1
- package/lib/Errors.js +3 -0
- package/lib/Errors.js.map +1 -1
- package/lib/common/AuthErrorStrings.d.ts +2 -1
- package/lib/common/AuthErrorStrings.js +1 -0
- package/lib/common/AuthErrorStrings.js.map +1 -1
- package/lib/types/Auth.d.ts +11 -1
- package/lib/types/Auth.js +1 -0
- package/lib/types/Auth.js.map +1 -1
- package/lib-esm/Auth.d.ts +6 -0
- package/lib-esm/Auth.js +124 -9
- package/lib-esm/Auth.js.map +1 -1
- package/lib-esm/Errors.js +3 -0
- package/lib-esm/Errors.js.map +1 -1
- package/lib-esm/common/AuthErrorStrings.d.ts +2 -1
- package/lib-esm/common/AuthErrorStrings.js +1 -0
- package/lib-esm/common/AuthErrorStrings.js.map +1 -1
- package/lib-esm/types/Auth.d.ts +11 -1
- package/lib-esm/types/Auth.js +1 -0
- package/lib-esm/types/Auth.js.map +1 -1
- package/package.json +5 -5
- package/src/Auth.ts +152 -0
- package/src/Errors.ts +3 -0
- package/src/common/AuthErrorStrings.ts +1 -0
- package/src/types/Auth.ts +9 -0
package/dist/aws-amplify-auth.js
CHANGED
|
@@ -10710,6 +10710,7 @@ var dispatchAuthEvent = function dispatchAuthEvent(event, data, message) {
|
|
|
10710
10710
|
|
|
10711
10711
|
|
|
10712
10712
|
var MAX_DEVICES = 60;
|
|
10713
|
+
var MAX_AUTOSIGNIN_POLLING_MS = 3 * 60 * 1000;
|
|
10713
10714
|
/**
|
|
10714
10715
|
* Provide authentication steps
|
|
10715
10716
|
*/
|
|
@@ -10727,6 +10728,7 @@ function () {
|
|
|
10727
10728
|
this.userPool = null;
|
|
10728
10729
|
this.user = null;
|
|
10729
10730
|
this.oAuthFlowInProgress = false;
|
|
10731
|
+
this.autoSignInInitiated = false;
|
|
10730
10732
|
this.Credentials = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Credentials"];
|
|
10731
10733
|
|
|
10732
10734
|
this.wrapRefreshSessionCallback = function (callback) {
|
|
@@ -10872,6 +10874,19 @@ function () {
|
|
|
10872
10874
|
}
|
|
10873
10875
|
|
|
10874
10876
|
dispatchAuthEvent('configured', null, "The Auth category has been configured successfully");
|
|
10877
|
+
|
|
10878
|
+
if (!this.autoSignInInitiated && typeof this._storage['getItem'] === 'function') {
|
|
10879
|
+
var pollingInitiated = this.isTrueStorageValue('amplify-polling-started');
|
|
10880
|
+
|
|
10881
|
+
if (pollingInitiated) {
|
|
10882
|
+
dispatchAuthEvent('autoSignIn_failure', null, _types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].AutoSignInError);
|
|
10883
|
+
|
|
10884
|
+
this._storage.removeItem('amplify-auto-sign-in');
|
|
10885
|
+
}
|
|
10886
|
+
|
|
10887
|
+
this._storage.removeItem('amplify-polling-started');
|
|
10888
|
+
}
|
|
10889
|
+
|
|
10875
10890
|
return this._config;
|
|
10876
10891
|
};
|
|
10877
10892
|
/**
|
|
@@ -10891,6 +10906,8 @@ function () {
|
|
|
10891
10906
|
restOfAttrs[_i - 1] = arguments[_i];
|
|
10892
10907
|
}
|
|
10893
10908
|
|
|
10909
|
+
var _a, _b, _c;
|
|
10910
|
+
|
|
10894
10911
|
if (!this.userPool) {
|
|
10895
10912
|
return this.rejectNoUserPool();
|
|
10896
10913
|
}
|
|
@@ -10900,6 +10917,11 @@ function () {
|
|
|
10900
10917
|
var attributes = [];
|
|
10901
10918
|
var validationData = null;
|
|
10902
10919
|
var clientMetadata;
|
|
10920
|
+
var autoSignIn = {
|
|
10921
|
+
enabled: false
|
|
10922
|
+
};
|
|
10923
|
+
var autoSignInValidationData = {};
|
|
10924
|
+
var autoSignInClientMetaData = {};
|
|
10903
10925
|
|
|
10904
10926
|
if (params && typeof params === 'string') {
|
|
10905
10927
|
username = params;
|
|
@@ -10946,6 +10968,17 @@ function () {
|
|
|
10946
10968
|
}));
|
|
10947
10969
|
});
|
|
10948
10970
|
}
|
|
10971
|
+
|
|
10972
|
+
autoSignIn = (_a = params.autoSignIn) !== null && _a !== void 0 ? _a : {
|
|
10973
|
+
enabled: false
|
|
10974
|
+
};
|
|
10975
|
+
|
|
10976
|
+
if (autoSignIn.enabled) {
|
|
10977
|
+
this._storage.setItem('amplify-auto-sign-in', true);
|
|
10978
|
+
|
|
10979
|
+
autoSignInValidationData = (_b = autoSignIn.validationData) !== null && _b !== void 0 ? _b : {};
|
|
10980
|
+
autoSignInClientMetaData = (_c = autoSignIn.clientMetaData) !== null && _c !== void 0 ? _c : {};
|
|
10981
|
+
}
|
|
10949
10982
|
} else {
|
|
10950
10983
|
return this.rejectAuthError(_types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].SignUpError);
|
|
10951
10984
|
}
|
|
@@ -10967,11 +11000,126 @@ function () {
|
|
|
10967
11000
|
reject(err);
|
|
10968
11001
|
} else {
|
|
10969
11002
|
dispatchAuthEvent('signUp', data, username + " has signed up successfully");
|
|
11003
|
+
|
|
11004
|
+
if (autoSignIn.enabled) {
|
|
11005
|
+
_this.handleAutoSignIn(username, password, autoSignInValidationData, autoSignInClientMetaData, data);
|
|
11006
|
+
}
|
|
11007
|
+
|
|
10970
11008
|
resolve(data);
|
|
10971
11009
|
}
|
|
10972
11010
|
}, clientMetadata);
|
|
10973
11011
|
});
|
|
10974
11012
|
};
|
|
11013
|
+
|
|
11014
|
+
AuthClass.prototype.handleAutoSignIn = function (username, password, validationData, clientMetadata, data) {
|
|
11015
|
+
this.autoSignInInitiated = true;
|
|
11016
|
+
var authDetails = new amazon_cognito_identity_js__WEBPACK_IMPORTED_MODULE_2__["AuthenticationDetails"]({
|
|
11017
|
+
Username: username,
|
|
11018
|
+
Password: password,
|
|
11019
|
+
ValidationData: validationData,
|
|
11020
|
+
ClientMetadata: clientMetadata
|
|
11021
|
+
});
|
|
11022
|
+
|
|
11023
|
+
if (data.userConfirmed) {
|
|
11024
|
+
this.signInAfterUserConfirmed(authDetails);
|
|
11025
|
+
} else if (this._config.signUpVerificationMethod === 'link') {
|
|
11026
|
+
this.handleLinkAutoSignIn(authDetails);
|
|
11027
|
+
} else {
|
|
11028
|
+
this.handleCodeAutoSignIn(authDetails);
|
|
11029
|
+
}
|
|
11030
|
+
};
|
|
11031
|
+
|
|
11032
|
+
AuthClass.prototype.handleCodeAutoSignIn = function (authDetails) {
|
|
11033
|
+
var _this = this;
|
|
11034
|
+
|
|
11035
|
+
var listenEvent = function listenEvent(_a) {
|
|
11036
|
+
var payload = _a.payload;
|
|
11037
|
+
|
|
11038
|
+
if (payload.event === 'confirmSignUp') {
|
|
11039
|
+
_this.signInAfterUserConfirmed(authDetails, listenEvent);
|
|
11040
|
+
}
|
|
11041
|
+
};
|
|
11042
|
+
|
|
11043
|
+
_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Hub"].listen('auth', listenEvent);
|
|
11044
|
+
};
|
|
11045
|
+
|
|
11046
|
+
AuthClass.prototype.handleLinkAutoSignIn = function (authDetails) {
|
|
11047
|
+
var _this = this;
|
|
11048
|
+
|
|
11049
|
+
this._storage.setItem('amplify-polling-started', true);
|
|
11050
|
+
|
|
11051
|
+
var start = Date.now();
|
|
11052
|
+
var autoSignInPollingIntervalId = setInterval(function () {
|
|
11053
|
+
if (Date.now() - start > MAX_AUTOSIGNIN_POLLING_MS) {
|
|
11054
|
+
clearInterval(autoSignInPollingIntervalId);
|
|
11055
|
+
dispatchAuthEvent('autoSignIn_failure', null, 'Please confirm your account and use your credentials to sign in.');
|
|
11056
|
+
|
|
11057
|
+
_this._storage.removeItem('amplify-auto-sign-in');
|
|
11058
|
+
} else {
|
|
11059
|
+
_this.signInAfterUserConfirmed(authDetails, null, autoSignInPollingIntervalId);
|
|
11060
|
+
}
|
|
11061
|
+
}, 5000);
|
|
11062
|
+
};
|
|
11063
|
+
|
|
11064
|
+
AuthClass.prototype.signInAfterUserConfirmed = function (authDetails, listenEvent, autoSignInPollingIntervalId) {
|
|
11065
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
11066
|
+
var user, error_1;
|
|
11067
|
+
|
|
11068
|
+
var _this = this;
|
|
11069
|
+
|
|
11070
|
+
return __generator(this, function (_a) {
|
|
11071
|
+
switch (_a.label) {
|
|
11072
|
+
case 0:
|
|
11073
|
+
user = this.createCognitoUser(authDetails.getUsername());
|
|
11074
|
+
_a.label = 1;
|
|
11075
|
+
|
|
11076
|
+
case 1:
|
|
11077
|
+
_a.trys.push([1, 3,, 4]);
|
|
11078
|
+
|
|
11079
|
+
return [4
|
|
11080
|
+
/*yield*/
|
|
11081
|
+
, user.authenticateUser(authDetails, this.authCallbacks(user, function (value) {
|
|
11082
|
+
dispatchAuthEvent('autoSignIn', value, authDetails.getUsername() + " has signed in successfully");
|
|
11083
|
+
|
|
11084
|
+
if (listenEvent) {
|
|
11085
|
+
_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Hub"].remove('auth', listenEvent);
|
|
11086
|
+
}
|
|
11087
|
+
|
|
11088
|
+
if (autoSignInPollingIntervalId) {
|
|
11089
|
+
clearInterval(autoSignInPollingIntervalId);
|
|
11090
|
+
|
|
11091
|
+
_this._storage.removeItem('amplify-polling-started');
|
|
11092
|
+
}
|
|
11093
|
+
|
|
11094
|
+
_this._storage.removeItem('amplify-auto-sign-in');
|
|
11095
|
+
}, function (error) {
|
|
11096
|
+
logger.error(error);
|
|
11097
|
+
|
|
11098
|
+
_this._storage.removeItem('amplify-auto-sign-in');
|
|
11099
|
+
}))];
|
|
11100
|
+
|
|
11101
|
+
case 2:
|
|
11102
|
+
_a.sent();
|
|
11103
|
+
|
|
11104
|
+
return [3
|
|
11105
|
+
/*break*/
|
|
11106
|
+
, 4];
|
|
11107
|
+
|
|
11108
|
+
case 3:
|
|
11109
|
+
error_1 = _a.sent();
|
|
11110
|
+
logger.error(error_1);
|
|
11111
|
+
return [3
|
|
11112
|
+
/*break*/
|
|
11113
|
+
, 4];
|
|
11114
|
+
|
|
11115
|
+
case 4:
|
|
11116
|
+
return [2
|
|
11117
|
+
/*return*/
|
|
11118
|
+
];
|
|
11119
|
+
}
|
|
11120
|
+
});
|
|
11121
|
+
});
|
|
11122
|
+
};
|
|
10975
11123
|
/**
|
|
10976
11124
|
* Send the verification code to confirm sign up
|
|
10977
11125
|
* @param {String} username - The username to be confirmed
|
|
@@ -10982,6 +11130,8 @@ function () {
|
|
|
10982
11130
|
|
|
10983
11131
|
|
|
10984
11132
|
AuthClass.prototype.confirmSignUp = function (username, code, options) {
|
|
11133
|
+
var _this = this;
|
|
11134
|
+
|
|
10985
11135
|
if (!this.userPool) {
|
|
10986
11136
|
return this.rejectNoUserPool();
|
|
10987
11137
|
}
|
|
@@ -11009,11 +11159,27 @@ function () {
|
|
|
11009
11159
|
if (err) {
|
|
11010
11160
|
reject(err);
|
|
11011
11161
|
} else {
|
|
11162
|
+
dispatchAuthEvent('confirmSignUp', data, username + " has been confirmed successfully");
|
|
11163
|
+
|
|
11164
|
+
var autoSignIn = _this.isTrueStorageValue('amplify-auto-sign-in');
|
|
11165
|
+
|
|
11166
|
+
if (autoSignIn && !_this.autoSignInInitiated) {
|
|
11167
|
+
dispatchAuthEvent('autoSignIn_failure', null, _types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].AutoSignInError);
|
|
11168
|
+
|
|
11169
|
+
_this._storage.removeItem('amplify-auto-sign-in');
|
|
11170
|
+
}
|
|
11171
|
+
|
|
11012
11172
|
resolve(data);
|
|
11013
11173
|
}
|
|
11014
11174
|
}, clientMetadata);
|
|
11015
11175
|
});
|
|
11016
11176
|
};
|
|
11177
|
+
|
|
11178
|
+
AuthClass.prototype.isTrueStorageValue = function (value) {
|
|
11179
|
+
var item = this._storage.getItem(value);
|
|
11180
|
+
|
|
11181
|
+
return item ? item === 'true' : false;
|
|
11182
|
+
};
|
|
11017
11183
|
/**
|
|
11018
11184
|
* Resend the verification code
|
|
11019
11185
|
* @param {String} username - The username to be confirmed
|
|
@@ -13711,7 +13877,7 @@ function () {
|
|
|
13711
13877
|
|
|
13712
13878
|
AuthClass.prototype.rememberDevice = function () {
|
|
13713
13879
|
return __awaiter(this, void 0, void 0, function () {
|
|
13714
|
-
var currUser,
|
|
13880
|
+
var currUser, error_2;
|
|
13715
13881
|
return __generator(this, function (_a) {
|
|
13716
13882
|
switch (_a.label) {
|
|
13717
13883
|
case 0:
|
|
@@ -13728,8 +13894,8 @@ function () {
|
|
|
13728
13894
|
, 3];
|
|
13729
13895
|
|
|
13730
13896
|
case 2:
|
|
13731
|
-
|
|
13732
|
-
logger.debug('The user is not authenticated by the error',
|
|
13897
|
+
error_2 = _a.sent();
|
|
13898
|
+
logger.debug('The user is not authenticated by the error', error_2);
|
|
13733
13899
|
return [2
|
|
13734
13900
|
/*return*/
|
|
13735
13901
|
, Promise.reject('The user is not authenticated')];
|
|
@@ -13761,7 +13927,7 @@ function () {
|
|
|
13761
13927
|
|
|
13762
13928
|
AuthClass.prototype.forgetDevice = function () {
|
|
13763
13929
|
return __awaiter(this, void 0, void 0, function () {
|
|
13764
|
-
var currUser,
|
|
13930
|
+
var currUser, error_3;
|
|
13765
13931
|
return __generator(this, function (_a) {
|
|
13766
13932
|
switch (_a.label) {
|
|
13767
13933
|
case 0:
|
|
@@ -13778,8 +13944,8 @@ function () {
|
|
|
13778
13944
|
, 3];
|
|
13779
13945
|
|
|
13780
13946
|
case 2:
|
|
13781
|
-
|
|
13782
|
-
logger.debug('The user is not authenticated by the error',
|
|
13947
|
+
error_3 = _a.sent();
|
|
13948
|
+
logger.debug('The user is not authenticated by the error', error_3);
|
|
13783
13949
|
return [2
|
|
13784
13950
|
/*return*/
|
|
13785
13951
|
, Promise.reject('The user is not authenticated')];
|
|
@@ -13811,7 +13977,7 @@ function () {
|
|
|
13811
13977
|
|
|
13812
13978
|
AuthClass.prototype.fetchDevices = function () {
|
|
13813
13979
|
return __awaiter(this, void 0, void 0, function () {
|
|
13814
|
-
var currUser,
|
|
13980
|
+
var currUser, error_4;
|
|
13815
13981
|
return __generator(this, function (_a) {
|
|
13816
13982
|
switch (_a.label) {
|
|
13817
13983
|
case 0:
|
|
@@ -13828,8 +13994,8 @@ function () {
|
|
|
13828
13994
|
, 3];
|
|
13829
13995
|
|
|
13830
13996
|
case 2:
|
|
13831
|
-
|
|
13832
|
-
logger.debug('The user is not authenticated by the error',
|
|
13997
|
+
error_4 = _a.sent();
|
|
13998
|
+
logger.debug('The user is not authenticated by the error', error_4);
|
|
13833
13999
|
throw new Error('The user is not authenticated');
|
|
13834
14000
|
|
|
13835
14001
|
case 3:
|
|
@@ -14026,6 +14192,9 @@ var authErrorMessages = {
|
|
|
14026
14192
|
networkError: {
|
|
14027
14193
|
message: _common_AuthErrorStrings__WEBPACK_IMPORTED_MODULE_1__["AuthErrorStrings"].NETWORK_ERROR
|
|
14028
14194
|
},
|
|
14195
|
+
autoSignInError: {
|
|
14196
|
+
message: _common_AuthErrorStrings__WEBPACK_IMPORTED_MODULE_1__["AuthErrorStrings"].AUTOSIGNIN_ERROR
|
|
14197
|
+
},
|
|
14029
14198
|
"default": {
|
|
14030
14199
|
message: _common_AuthErrorStrings__WEBPACK_IMPORTED_MODULE_1__["AuthErrorStrings"].DEFAULT_MSG
|
|
14031
14200
|
}
|
|
@@ -14753,6 +14922,7 @@ var AuthErrorStrings;
|
|
|
14753
14922
|
AuthErrorStrings["NO_USER_SESSION"] = "Failed to get the session because the user is empty";
|
|
14754
14923
|
AuthErrorStrings["NETWORK_ERROR"] = "Network Error";
|
|
14755
14924
|
AuthErrorStrings["DEVICE_CONFIG"] = "Device tracking has not been configured in this User Pool";
|
|
14925
|
+
AuthErrorStrings["AUTOSIGNIN_ERROR"] = "Please use your credentials to sign in";
|
|
14756
14926
|
})(AuthErrorStrings || (AuthErrorStrings = {}));
|
|
14757
14927
|
|
|
14758
14928
|
/***/ }),
|
|
@@ -14886,6 +15056,7 @@ var AuthErrorTypes;
|
|
|
14886
15056
|
AuthErrorTypes["Default"] = "default";
|
|
14887
15057
|
AuthErrorTypes["DeviceConfig"] = "deviceConfig";
|
|
14888
15058
|
AuthErrorTypes["NetworkError"] = "networkError";
|
|
15059
|
+
AuthErrorTypes["AutoSignInError"] = "autoSignInError";
|
|
14889
15060
|
})(AuthErrorTypes || (AuthErrorTypes = {}));
|
|
14890
15061
|
|
|
14891
15062
|
function isUsernamePasswordOpts(obj) {
|