From a20e935268c986538ff68f72016bb8c772ea3a1b Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Thu, 14 Oct 2021 10:27:52 +1000 Subject: [PATCH] Use rxjs first instead of unsubscribe (#516) --- angular/src/components/set-password.component.ts | 9 +++------ angular/src/components/sso.component.ts | 7 +++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/angular/src/components/set-password.component.ts b/angular/src/components/set-password.component.ts index 779559e6..c12e32e6 100644 --- a/angular/src/components/set-password.component.ts +++ b/angular/src/components/set-password.component.ts @@ -4,6 +4,8 @@ import { Router } from '@angular/router'; +import { first } from 'rxjs/operators'; + import { ApiService } from 'jslib-common/abstractions/api.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; @@ -25,7 +27,6 @@ import { ChangePasswordComponent as BaseChangePasswordComponent } from './change import { HashPurpose } from 'jslib-common/enums/hashPurpose'; import { KdfType } from 'jslib-common/enums/kdfType'; -import { PolicyType } from 'jslib-common/enums/policyType'; import { Utils } from 'jslib-common/misc/utils'; @@ -53,14 +54,10 @@ export class SetPasswordComponent extends BaseChangePasswordComponent { await this.syncService.fullSync(true); this.syncLoading = false; - const queryParamsSub = this.route.queryParams.subscribe(async qParams => { + this.route.queryParams.pipe(first()).subscribe(async qParams => { if (qParams.identifier != null) { this.identifier = qParams.identifier; } - - if (queryParamsSub != null) { - queryParamsSub.unsubscribe(); - } }); // Automatic Enrollment Detection diff --git a/angular/src/components/sso.component.ts b/angular/src/components/sso.component.ts index 128ab969..6f55641c 100644 --- a/angular/src/components/sso.component.ts +++ b/angular/src/components/sso.component.ts @@ -4,6 +4,8 @@ import { Router, } from '@angular/router'; +import { first } from 'rxjs/operators'; + import { ApiService } from 'jslib-common/abstractions/api.service'; import { AuthService } from 'jslib-common/abstractions/auth.service'; import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service'; @@ -50,7 +52,7 @@ export class SsoComponent { protected passwordGenerationService: PasswordGenerationService) { } async ngOnInit() { - const queryParamsSub = this.route.queryParams.subscribe(async qParams => { + this.route.queryParams.pipe(first()).subscribe(async qParams => { if (qParams.code != null && qParams.state != null) { const codeVerifier = await this.storageService.get(ConstantsService.ssoCodeVerifierKey); const state = await this.storageService.get(ConstantsService.ssoStateKey); @@ -66,9 +68,6 @@ export class SsoComponent { this.codeChallenge = qParams.codeChallenge; this.clientId = qParams.clientId; } - if (queryParamsSub != null) { - queryParamsSub.unsubscribe(); - } }); }