From d098ee0cbc629dcfd1056b30afe03bef79f8883e Mon Sep 17 00:00:00 2001 From: rr-bw <102181210+rr-bw@users.noreply.github.com> Date: Tue, 10 Sep 2024 14:10:02 -0700 Subject: [PATCH] refactor submit logic further to use if statements with returns instead of if...else if...else --- .../auth/src/angular/login/login.component.ts | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/libs/auth/src/angular/login/login.component.ts b/libs/auth/src/angular/login/login.component.ts index 2fef83ac08..89ba46a5d9 100644 --- a/libs/auth/src/angular/login/login.component.ts +++ b/libs/auth/src/angular/login/login.component.ts @@ -184,24 +184,34 @@ export class LoginComponentV2 implements OnInit, OnDestroy { message: this.i18nService.t("encryptionKeyMigrationRequired"), }); } - } else if (authResult.requiresTwoFactor) { + return; + } + + if (authResult.requiresTwoFactor) { await this.router.navigate(["2fa"]); - } else if (authResult.forcePasswordReset != ForceSetPasswordReason.None) { + return; + } + + if (authResult.forcePasswordReset != ForceSetPasswordReason.None) { this.loginEmailService.clearValues(); await this.router.navigate(["update-temp-password"]); + return; + } + + // If none of the above cases are true, proceed with login... + // ...on Web + if (this.clientType === ClientType.Web) { + await this.goAfterLogIn(authResult.userId); + + // ...on Browser/Desktop } else { - if (this.clientType === ClientType.Web) { - await this.goAfterLogIn(authResult.userId); + await this.syncService.fullSync(true); // TODO-rr-bw: browser used `await`, desktop used `return`. Why? + this.loginEmailService.clearValues(); + + if (this.clientType === ClientType.Browser) { + await this.router.navigate(["/tabs/vault"]); } else { - await this.syncService.fullSync(true); // TODO-rr-bw: browser used `await`, desktop used `return`. Why? - - this.loginEmailService.clearValues(); - - if (this.clientType === ClientType.Browser) { - await this.router.navigate(["/tabs/vault"]); - } else { - await this.router.navigate(["vault"]); // Desktop - } + await this.router.navigate(["vault"]); // Desktop } } };