@aws-amplify/auth 5.1.6 → 5.1.7-push-notification-dryrun.43
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/lib/Auth.js +61 -41
- package/lib/Auth.js.map +1 -1
- package/lib/OAuth/OAuth.js +1 -1
- package/lib-esm/Auth.js +61 -41
- package/lib-esm/Auth.js.map +1 -1
- package/lib-esm/OAuth/OAuth.js +1 -1
- package/package.json +6 -5
- package/src/Auth.ts +43 -14
- package/src/OAuth/OAuth.ts +1 -1
- package/CHANGELOG.md +0 -2066
package/src/Auth.ts
CHANGED
|
@@ -159,9 +159,10 @@ export class AuthClass {
|
|
|
159
159
|
identityPoolRegion,
|
|
160
160
|
clientMetadata,
|
|
161
161
|
endpoint,
|
|
162
|
+
storage,
|
|
162
163
|
} = this._config;
|
|
163
164
|
|
|
164
|
-
if (!
|
|
165
|
+
if (!storage) {
|
|
165
166
|
// backward compatability
|
|
166
167
|
if (cookieStorage) this._storage = new CookieStorage(cookieStorage);
|
|
167
168
|
else {
|
|
@@ -170,11 +171,11 @@ export class AuthClass {
|
|
|
170
171
|
: new StorageHelper().getStorage();
|
|
171
172
|
}
|
|
172
173
|
} else {
|
|
173
|
-
if (!this._isValidAuthStorage(
|
|
174
|
+
if (!this._isValidAuthStorage(storage)) {
|
|
174
175
|
logger.error('The storage in the Auth config is not valid!');
|
|
175
176
|
throw new Error('Empty storage object');
|
|
176
177
|
}
|
|
177
|
-
this._storage =
|
|
178
|
+
this._storage = storage;
|
|
178
179
|
}
|
|
179
180
|
|
|
180
181
|
this._storageSync = Promise.resolve();
|
|
@@ -203,7 +204,7 @@ export class AuthClass {
|
|
|
203
204
|
identityPoolId,
|
|
204
205
|
refreshHandlers,
|
|
205
206
|
storage: this._storage,
|
|
206
|
-
identityPoolRegion
|
|
207
|
+
identityPoolRegion,
|
|
207
208
|
});
|
|
208
209
|
|
|
209
210
|
// initialize cognitoauth client if hosted ui options provided
|
|
@@ -1131,6 +1132,13 @@ export class AuthClass {
|
|
|
1131
1132
|
challengeAnswer: string
|
|
1132
1133
|
): Promise<CognitoUserSession> {
|
|
1133
1134
|
logger.debug('verification totp token', user, challengeAnswer);
|
|
1135
|
+
|
|
1136
|
+
let signInUserSession;
|
|
1137
|
+
if (user && typeof user.getSignInUserSession === 'function') {
|
|
1138
|
+
signInUserSession = (user as CognitoUser).getSignInUserSession();
|
|
1139
|
+
}
|
|
1140
|
+
const isLoggedIn = signInUserSession?.isValid();
|
|
1141
|
+
|
|
1134
1142
|
return new Promise((res, rej) => {
|
|
1135
1143
|
user.verifySoftwareToken(challengeAnswer, 'My TOTP device', {
|
|
1136
1144
|
onFailure: err => {
|
|
@@ -1139,7 +1147,13 @@ export class AuthClass {
|
|
|
1139
1147
|
return;
|
|
1140
1148
|
},
|
|
1141
1149
|
onSuccess: data => {
|
|
1142
|
-
|
|
1150
|
+
if (!isLoggedIn) {
|
|
1151
|
+
dispatchAuthEvent(
|
|
1152
|
+
'signIn',
|
|
1153
|
+
user,
|
|
1154
|
+
`A user ${user.getUsername()} has been signed in`
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
1143
1157
|
dispatchAuthEvent(
|
|
1144
1158
|
'verify',
|
|
1145
1159
|
user,
|
|
@@ -1183,7 +1197,12 @@ export class AuthClass {
|
|
|
1183
1197
|
logger.debug('cannot get cognito credentials', e);
|
|
1184
1198
|
} finally {
|
|
1185
1199
|
that.user = user;
|
|
1186
|
-
|
|
1200
|
+
try {
|
|
1201
|
+
const currentUser = await this.currentUserPoolUser();
|
|
1202
|
+
user.attributes = currentUser.attributes;
|
|
1203
|
+
} catch (e) {
|
|
1204
|
+
logger.debug('cannot get updated Cognito User', e);
|
|
1205
|
+
}
|
|
1187
1206
|
dispatchAuthEvent(
|
|
1188
1207
|
'signIn',
|
|
1189
1208
|
user,
|
|
@@ -1428,15 +1447,23 @@ export class AuthClass {
|
|
|
1428
1447
|
user.updateAttributes(
|
|
1429
1448
|
attributeList,
|
|
1430
1449
|
(err, result, details) => {
|
|
1431
|
-
|
|
1432
1450
|
if (err) {
|
|
1433
|
-
dispatchAuthEvent(
|
|
1451
|
+
dispatchAuthEvent(
|
|
1452
|
+
'updateUserAttributes_failure',
|
|
1453
|
+
err,
|
|
1454
|
+
'Failed to update attributes'
|
|
1455
|
+
);
|
|
1434
1456
|
return reject(err);
|
|
1435
1457
|
} else {
|
|
1436
1458
|
const attrs = this.createUpdateAttributesResultList(
|
|
1437
|
-
attributes as Record<string, string>,
|
|
1459
|
+
attributes as Record<string, string>,
|
|
1460
|
+
details?.CodeDeliveryDetailsList
|
|
1461
|
+
);
|
|
1462
|
+
dispatchAuthEvent(
|
|
1463
|
+
'updateUserAttributes',
|
|
1464
|
+
attrs,
|
|
1465
|
+
'Attributes successfully updated'
|
|
1438
1466
|
);
|
|
1439
|
-
dispatchAuthEvent('updateUserAttributes', attrs, 'Attributes successfully updated');
|
|
1440
1467
|
return resolve(result);
|
|
1441
1468
|
}
|
|
1442
1469
|
},
|
|
@@ -1447,15 +1474,17 @@ export class AuthClass {
|
|
|
1447
1474
|
}
|
|
1448
1475
|
|
|
1449
1476
|
private createUpdateAttributesResultList(
|
|
1450
|
-
attributes: Record<string, string>,
|
|
1451
|
-
codeDeliveryDetailsList?: CodeDeliveryDetails
|
|
1477
|
+
attributes: Record<string, string>,
|
|
1478
|
+
codeDeliveryDetailsList?: CodeDeliveryDetails[]
|
|
1452
1479
|
): Record<string, string> {
|
|
1453
1480
|
const attrs = {};
|
|
1454
1481
|
Object.keys(attributes).forEach(key => {
|
|
1455
1482
|
attrs[key] = {
|
|
1456
|
-
isUpdated: true
|
|
1483
|
+
isUpdated: true,
|
|
1457
1484
|
};
|
|
1458
|
-
const codeDeliveryDetails = codeDeliveryDetailsList?.find(
|
|
1485
|
+
const codeDeliveryDetails = codeDeliveryDetailsList?.find(
|
|
1486
|
+
value => value.AttributeName === key
|
|
1487
|
+
);
|
|
1459
1488
|
if (codeDeliveryDetails) {
|
|
1460
1489
|
attrs[key].isUpdated = false;
|
|
1461
1490
|
attrs[key].codeDeliveryDetails = codeDeliveryDetails;
|
package/src/OAuth/OAuth.ts
CHANGED
|
@@ -233,7 +233,7 @@ export default class OAuth {
|
|
|
233
233
|
return { ...(await this._handleImplicitFlow(currentUrl)), state };
|
|
234
234
|
}
|
|
235
235
|
} catch (e) {
|
|
236
|
-
logger.
|
|
236
|
+
logger.debug(`Error handling auth response.`, e);
|
|
237
237
|
throw e;
|
|
238
238
|
}
|
|
239
239
|
}
|