@aws-amplify/ui-angular 2.4.0 → 2.4.1

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.
@@ -91,15 +91,12 @@
91
91
  _this._authState = state;
92
92
  _this._facade = ui.getServiceContextFacade(state);
93
93
  });
94
- this._hubSubscription = ui.listenToAuthHub(authService.send);
95
94
  this._sendEventAliases = ui.getSendEventAliases(authService.send);
96
95
  this._authService = authService;
97
96
  }
98
97
  AuthenticatorService.prototype.ngOnDestroy = function () {
99
98
  if (this._machineSubscription)
100
99
  this._machineSubscription.unsubscribe();
101
- if (this._hubSubscription)
102
- this._hubSubscription();
103
100
  };
104
101
  Object.defineProperty(AuthenticatorService.prototype, "error", {
105
102
  /**
@@ -304,24 +301,55 @@
304
301
  AuthenticatorService.ctorParameters = function () { return []; };
305
302
 
306
303
  var AuthenticatorComponent = /** @class */ (function () {
307
- function AuthenticatorComponent(authenticator, contextService) {
304
+ function AuthenticatorComponent(authenticator, contextService, changeDetector) {
308
305
  this.authenticator = authenticator;
309
306
  this.contextService = contextService;
307
+ this.changeDetector = changeDetector;
310
308
  this.customComponentQuery = null;
311
309
  // translated texts
312
310
  this.signInTitle = ui.translate('Sign In');
313
311
  this.signUpTitle = ui.translate('Create Account');
314
312
  this.hasInitialized = false;
313
+ this.isHandlingHubEvent = false;
315
314
  }
316
315
  AuthenticatorComponent.prototype.ngOnInit = function () {
317
316
  var _this = this;
318
317
  var _a = this, initialState = _a.initialState, loginMechanisms = _a.loginMechanisms, services = _a.services, signUpAttributes = _a.signUpAttributes, socialProviders = _a.socialProviders, formFields = _a.formFields;
318
+ this.unsubscribeHub = ui.listenToAuthHub(function (event) {
319
+ /**
320
+ * Hub events aren't properly caught by Angular, because they are
321
+ * synchronous events. Angular tracks async network events and
322
+ * html events, but not synchronous events like hub.
323
+ *
324
+ * On any notable hub events, we run change detection manually.
325
+ */
326
+ var state = _this.authenticator.authService.send(event);
327
+ _this.changeDetector.detectChanges();
328
+ /**
329
+ * Hub events that we handle can lead to multiple state changes:
330
+ * e.g. `authenticated` -> `signOut` -> initialState.
331
+ *
332
+ * We want to ensure change detection runs all the way, until
333
+ * we reach back to the initial state. Setting the below flag
334
+ * to true to until we reach initial state.
335
+ */
336
+ _this.isHandlingHubEvent = true;
337
+ return state;
338
+ });
319
339
  /**
320
340
  * Subscribes to state machine changes and sends INIT event
321
341
  * once machine reaches 'setup' state.
322
342
  */
323
343
  this.unsubscribeMachine = this.authenticator.subscribe(function () {
324
344
  var route = _this.authenticator.route;
345
+ if (_this.isHandlingHubEvent) {
346
+ _this.changeDetector.detectChanges();
347
+ var initialStateWithDefault = initialState !== null && initialState !== void 0 ? initialState : 'signIn';
348
+ // We can stop manual change detection if we're back to the initial state
349
+ if (route === initialStateWithDefault) {
350
+ _this.isHandlingHubEvent = false;
351
+ }
352
+ }
325
353
  if (!_this.hasInitialized && route === 'setup') {
326
354
  _this.authenticator.send({
327
355
  type: 'INIT',
@@ -353,6 +381,8 @@
353
381
  AuthenticatorComponent.prototype.ngOnDestroy = function () {
354
382
  if (this.unsubscribeMachine)
355
383
  this.unsubscribeMachine();
384
+ if (this.unsubscribeHub)
385
+ this.unsubscribeHub();
356
386
  };
357
387
  Object.defineProperty(AuthenticatorComponent.prototype, "context", {
358
388
  /**
@@ -406,7 +436,8 @@
406
436
  ];
407
437
  AuthenticatorComponent.ctorParameters = function () { return [
408
438
  { type: AuthenticatorService },
409
- { type: CustomComponentsService }
439
+ { type: CustomComponentsService },
440
+ { type: i0.ChangeDetectorRef }
410
441
  ]; };
411
442
  AuthenticatorComponent.propDecorators = {
412
443
  formFields: [{ type: i0.Input }],
@@ -1203,7 +1234,7 @@
1203
1234
  _g.secretKey = _j.sent();
1204
1235
  issuer = (_c = (_b = (_a = this.formOverrides) === null || _a === void 0 ? void 0 : _a['QR']) === null || _b === void 0 ? void 0 : _b.totpIssuer) !== null && _c !== void 0 ? _c : 'AWSCognito';
1205
1236
  username = (_f = (_e = (_d = this.formOverrides) === null || _d === void 0 ? void 0 : _d['QR']) === null || _e === void 0 ? void 0 : _e.totpUsername) !== null && _f !== void 0 ? _f : user.username;
1206
- totpCode = "otpauth://totp/" + issuer + ":" + username + "?secret=" + this.secretKey + "&issuer=" + issuer;
1237
+ totpCode = encodeURI("otpauth://totp/" + issuer + ":" + username + "?secret=" + this.secretKey + "&issuer=" + issuer);
1207
1238
  logger.info('totp code was generated:', totpCode);
1208
1239
  _h = this;
1209
1240
  return [4 /*yield*/, QRCode__default["default"].toDataURL(totpCode)];