@aws-amplify/auth 4.3.21-unstable.9 → 4.4.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [4.4.0](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/auth@4.3.20...@aws-amplify/auth@4.4.0) (2022-01-27)
7
+
8
+
9
+ ### Features
10
+
11
+ * **@aws-amplify/auth:** Delete user API exposed ([#9428](https://github.com/aws-amplify/amplify-js/issues/9428)) ([bf3d189](https://github.com/aws-amplify/amplify-js/commit/bf3d189c9e7e14342230fca8a0cbba6972e7b42c))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [4.3.20](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/auth@4.3.19...@aws-amplify/auth@4.3.20) (2022-01-07)
7
18
 
8
19
  **Note:** Version bump only for package @aws-amplify/auth
@@ -12045,6 +12045,119 @@ function () {
12045
12045
  });
12046
12046
  });
12047
12047
  };
12048
+ /**
12049
+ * Delete the current authenticated user
12050
+ * @return {Promise}
12051
+ **/
12052
+ //TODO: Check return type void
12053
+
12054
+
12055
+ AuthClass.prototype.deleteUser = function () {
12056
+ return __awaiter(this, void 0, void 0, function () {
12057
+ var e_5, isSignedInHostedUI;
12058
+
12059
+ var _this = this;
12060
+
12061
+ return __generator(this, function (_a) {
12062
+ switch (_a.label) {
12063
+ case 0:
12064
+ _a.trys.push([0, 2,, 3]);
12065
+
12066
+ return [4
12067
+ /*yield*/
12068
+ , this._storageSync];
12069
+
12070
+ case 1:
12071
+ _a.sent();
12072
+
12073
+ return [3
12074
+ /*break*/
12075
+ , 3];
12076
+
12077
+ case 2:
12078
+ e_5 = _a.sent();
12079
+ logger.debug('Failed to sync cache info into memory', e_5);
12080
+ throw new Error(e_5);
12081
+
12082
+ case 3:
12083
+ isSignedInHostedUI = this._oAuthHandler && this._storage.getItem('amplify-signin-with-hostedUI') === 'true';
12084
+ return [2
12085
+ /*return*/
12086
+ , new Promise(function (res, rej) {
12087
+ return __awaiter(_this, void 0, void 0, function () {
12088
+ var user_1;
12089
+
12090
+ var _this = this;
12091
+
12092
+ return __generator(this, function (_a) {
12093
+ if (this.userPool) {
12094
+ user_1 = this.userPool.getCurrentUser();
12095
+
12096
+ if (!user_1) {
12097
+ logger.debug('Failed to get user from user pool');
12098
+ return [2
12099
+ /*return*/
12100
+ , rej(new Error('No current user.'))];
12101
+ } else {
12102
+ user_1.getSession(function (err, session) {
12103
+ return __awaiter(_this, void 0, void 0, function () {
12104
+ var _this = this;
12105
+
12106
+ return __generator(this, function (_a) {
12107
+ if (err) {
12108
+ logger.debug('Failed to get the user session', err);
12109
+ return [2
12110
+ /*return*/
12111
+ , rej(err)];
12112
+ } else {
12113
+ user_1.deleteUser(function (err, result) {
12114
+ if (err) {
12115
+ rej(err);
12116
+ } else {
12117
+ dispatchAuthEvent('userDeleted', result, 'The authenticated user has been deleted.');
12118
+ user_1.signOut();
12119
+ _this.user = null;
12120
+
12121
+ try {
12122
+ _this.cleanCachedItems(); // clean aws credentials
12123
+
12124
+ } catch (e) {
12125
+ // TODO: change to rejects in refactor
12126
+ logger.debug('failed to clear cached items');
12127
+ }
12128
+
12129
+ if (isSignedInHostedUI) {
12130
+ _this.oAuthSignOutRedirect(res, rej);
12131
+ } else {
12132
+ dispatchAuthEvent('signOut', _this.user, "A user has been signed out");
12133
+ res(result);
12134
+ }
12135
+ }
12136
+ });
12137
+ }
12138
+
12139
+ return [2
12140
+ /*return*/
12141
+ ];
12142
+ });
12143
+ });
12144
+ });
12145
+ }
12146
+ } else {
12147
+ logger.debug('no Congito User pool');
12148
+ rej(new Error('Cognito User pool does not exist'));
12149
+ }
12150
+
12151
+ return [2
12152
+ /*return*/
12153
+ ];
12154
+ });
12155
+ });
12156
+ })];
12157
+ }
12158
+ });
12159
+ });
12160
+ };
12048
12161
  /**
12049
12162
  * Update an authenticated users' attributes
12050
12163
  * @param {CognitoUser} - The currently logged in user object
@@ -12316,7 +12429,7 @@ function () {
12316
12429
 
12317
12430
  AuthClass.prototype.currentAuthenticatedUser = function (params) {
12318
12431
  return __awaiter(this, void 0, void 0, function () {
12319
- var federatedUser, e_5, federatedInfo, user, e_6;
12432
+ var federatedUser, e_6, federatedInfo, user, e_7;
12320
12433
  return __generator(this, function (_a) {
12321
12434
  switch (_a.label) {
12322
12435
  case 0:
@@ -12339,9 +12452,9 @@ function () {
12339
12452
  , 4];
12340
12453
 
12341
12454
  case 3:
12342
- e_5 = _a.sent();
12343
- logger.debug('Failed to sync cache info into memory', e_5);
12344
- throw e_5;
12455
+ e_6 = _a.sent();
12456
+ logger.debug('Failed to sync cache info into memory', e_6);
12457
+ throw e_6;
12345
12458
 
12346
12459
  case 4:
12347
12460
  try {
@@ -12384,13 +12497,13 @@ function () {
12384
12497
  , 9];
12385
12498
 
12386
12499
  case 8:
12387
- e_6 = _a.sent();
12500
+ e_7 = _a.sent();
12388
12501
 
12389
- if (e_6 === 'No userPool') {
12502
+ if (e_7 === 'No userPool') {
12390
12503
  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
12504
  }
12392
12505
 
12393
- logger.debug('The user is not authenticated by the error', e_6);
12506
+ logger.debug('The user is not authenticated by the error', e_7);
12394
12507
  return [2
12395
12508
  /*return*/
12396
12509
  , Promise.reject('The user is not authenticated')];
@@ -12475,7 +12588,7 @@ function () {
12475
12588
 
12476
12589
  AuthClass.prototype.currentUserCredentials = function () {
12477
12590
  return __awaiter(this, void 0, void 0, function () {
12478
- var e_7, federatedInfo;
12591
+ var e_8, federatedInfo;
12479
12592
 
12480
12593
  var _this = this;
12481
12594
 
@@ -12500,9 +12613,9 @@ function () {
12500
12613
  , 4];
12501
12614
 
12502
12615
  case 3:
12503
- e_7 = _a.sent();
12504
- logger.debug('Failed to sync cache info into memory', e_7);
12505
- throw e_7;
12616
+ e_8 = _a.sent();
12617
+ logger.debug('Failed to sync cache info into memory', e_8);
12618
+ throw e_8;
12506
12619
 
12507
12620
  case 4:
12508
12621
  federatedInfo = null;
@@ -12617,7 +12730,7 @@ function () {
12617
12730
 
12618
12731
  AuthClass.prototype.cognitoIdentitySignOut = function (opts, user) {
12619
12732
  return __awaiter(this, void 0, void 0, function () {
12620
- var e_8, isSignedInHostedUI;
12733
+ var e_9, isSignedInHostedUI;
12621
12734
 
12622
12735
  var _this = this;
12623
12736
 
@@ -12638,9 +12751,9 @@ function () {
12638
12751
  , 3];
12639
12752
 
12640
12753
  case 2:
12641
- e_8 = _a.sent();
12642
- logger.debug('Failed to sync cache info into memory', e_8);
12643
- throw e_8;
12754
+ e_9 = _a.sent();
12755
+ logger.debug('Failed to sync cache info into memory', e_9);
12756
+ throw e_9;
12644
12757
 
12645
12758
  case 3:
12646
12759
  isSignedInHostedUI = this._oAuthHandler && this._storage.getItem('amplify-signin-with-hostedUI') === 'true';
@@ -12727,7 +12840,7 @@ function () {
12727
12840
 
12728
12841
  AuthClass.prototype.signOut = function (opts) {
12729
12842
  return __awaiter(this, void 0, void 0, function () {
12730
- var e_9, user;
12843
+ var e_10, user;
12731
12844
  return __generator(this, function (_a) {
12732
12845
  switch (_a.label) {
12733
12846
  case 0:
@@ -12745,7 +12858,7 @@ function () {
12745
12858
  , 3];
12746
12859
 
12747
12860
  case 2:
12748
- e_9 = _a.sent();
12861
+ e_10 = _a.sent();
12749
12862
  logger.debug('failed to clear cached items');
12750
12863
  return [3
12751
12864
  /*break*/
@@ -12946,7 +13059,7 @@ function () {
12946
13059
 
12947
13060
  AuthClass.prototype.currentUserInfo = function () {
12948
13061
  return __awaiter(this, void 0, void 0, function () {
12949
- var source, user, attributes, userAttrs, credentials, e_10, info, err_1, user;
13062
+ var source, user, attributes, userAttrs, credentials, e_11, info, err_1, user;
12950
13063
  return __generator(this, function (_a) {
12951
13064
  switch (_a.label) {
12952
13065
  case 0:
@@ -12998,8 +13111,8 @@ function () {
12998
13111
  , 7];
12999
13112
 
13000
13113
  case 6:
13001
- e_10 = _a.sent();
13002
- logger.debug('Failed to retrieve credentials while getting current user info', e_10);
13114
+ e_11 = _a.sent();
13115
+ logger.debug('Failed to retrieve credentials while getting current user info', e_11);
13003
13116
  return [3
13004
13117
  /*break*/
13005
13118
  , 7];