@block-auth.io/angular 0.7.7 → 0.8.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.
@@ -10156,15 +10156,9 @@ class FlowBlockAuthComponent {
10156
10156
  return;
10157
10157
  let cancelled = false;
10158
10158
  const timer = setTimeout(async () => {
10159
- const resumed = await this.client.resumeSession();
10160
- if (cancelled)
10161
- return;
10162
- this.isReconnectingRemembered.set(false);
10163
- if (resumed) {
10164
- this.isRequestingSignin.set(false);
10165
- return;
10166
- }
10167
- untracked(() => this.requestReturningSignin());
10159
+ await untracked(() => this.resumeOrRequestSignin(() => cancelled));
10160
+ if (!cancelled)
10161
+ this.isReconnectingRemembered.set(false);
10168
10162
  }, REMEMBERED_SIGNIN_SETTLE_MS);
10169
10163
  onCleanup(() => {
10170
10164
  cancelled = true;
@@ -10177,9 +10171,25 @@ class FlowBlockAuthComponent {
10177
10171
  });
10178
10172
  }
10179
10173
  ngOnInit() {
10180
- if (!this.isHosted || this.user() !== undefined || !this.client.usesAuthEndpoint(Boolean(this.onAuthCode())))
10174
+ if (!this.isHosted)
10181
10175
  return;
10182
- this.client.restoreHostedLogin().catch(() => this.errored.emit());
10176
+ const authCode = this.onAuthCode();
10177
+ const ownsAuthCode = Boolean(authCode);
10178
+ const restoresSession = this.user() === undefined &&
10179
+ (this.client.hasAuthEndpoint ? this.client.usesAuthEndpoint(ownsAuthCode) : !ownsAuthCode);
10180
+ const redirectLogin = authCode
10181
+ ? this.client.completeRedirectAuthCode(authCode)
10182
+ : this.client.handleRedirectCallback();
10183
+ redirectLogin
10184
+ .then(async (redirectUser) => {
10185
+ if (redirectUser) {
10186
+ this.success.emit(redirectUser.address);
10187
+ return;
10188
+ }
10189
+ if (restoresSession)
10190
+ await this.client.restoreHostedLogin();
10191
+ })
10192
+ .catch(() => this.errored.emit());
10183
10193
  }
10184
10194
  onHostedLoginClicked() {
10185
10195
  if (this.isPopupOpen())
@@ -10231,9 +10241,20 @@ class FlowBlockAuthComponent {
10231
10241
  if (this.isRequestingSignin() || this.ui().isSigning)
10232
10242
  return;
10233
10243
  this.isRequestingSignin.set(true);
10234
- this.requestReturningSignin();
10244
+ void this.resumeOrRequestSignin();
10235
10245
  }
10236
10246
  }
10247
+ async resumeOrRequestSignin(isCancelled = () => false) {
10248
+ const resumed = await this.client.resumeSession();
10249
+ if (isCancelled())
10250
+ return;
10251
+ if (resumed) {
10252
+ this.isRequestingSignin.set(false);
10253
+ setIsSigningLoader(false);
10254
+ return;
10255
+ }
10256
+ this.requestReturningSignin();
10257
+ }
10237
10258
  requestReturningSignin() {
10238
10259
  // LOG-IN branch: emit the signin transaction, then open the signin modal
10239
10260
  // and flag the signing loader. The runtime clears the loader once
@@ -10528,7 +10549,17 @@ class LinkBlockAuthComponent {
10528
10549
  this.linkLabel = computed(() => this.linkDefault[this.locale()] ?? this.linkDefault['en'], ...(ngDevMode ? [{ debugName: "linkLabel" }] : []));
10529
10550
  }
10530
10551
  ngOnInit() {
10531
- void this.refreshStatus();
10552
+ this.client
10553
+ .completeRedirectLink()
10554
+ .then((linked) => {
10555
+ if (linked)
10556
+ this.linked.emit();
10557
+ return this.refreshStatus();
10558
+ })
10559
+ .catch((error) => {
10560
+ this.errored.emit(error instanceof AccountLinkError ? error.reason : 'failed');
10561
+ return this.refreshStatus();
10562
+ });
10532
10563
  }
10533
10564
  onLinkClicked() {
10534
10565
  if (this.isPopupOpen())