From bda7aff447e6dd07a9a36608cb4b496e54878c83 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 6 Jul 2026 23:15:52 +0200 Subject: [PATCH] fix(login): re-enable forms after failed auth requests --- .../modules/app-login/app-login.component.ts | 116 ++++++++++-------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/webapp/src/app/modules/app-login/app-login.component.ts b/webapp/src/app/modules/app-login/app-login.component.ts index a8bd7fea..fe894887 100644 --- a/webapp/src/app/modules/app-login/app-login.component.ts +++ b/webapp/src/app/modules/app-login/app-login.component.ts @@ -11,7 +11,7 @@ import { MatInputModule } from '@angular/material/input'; import { CredentialService } from '../../shared/services/credential.service'; import { MatIconModule } from '@angular/material/icon'; import { CommonModule } from '@angular/common'; -import { Subscription } from 'rxjs'; +import { finalize, Subscription } from 'rxjs'; import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; import { Router, RouterLink } from '@angular/router'; import { HttpErrorResponse } from '@angular/common/http'; @@ -103,35 +103,39 @@ export class AppLoginComponent implements OnDestroy { const email = this.credentialsForm.controls.email.value ?? ''; const password = this.credentialsForm.controls.password.value ?? ''; - this.credentialService.requestOtk(email, password).subscribe({ - next: (otkResponse) => { - const accountId = otkResponse.account_id; - this.accountId = accountId; - this.currentStep = 'otk'; - this.otkForm.reset(); - this.startCountdown(); - this.snackBar.open( - 'OTK-Code wurde an die E-Mail-Adresse gesendet.', - 'OK', - { - duration: 4000, - }, - ); - }, - error: (error: unknown) => { - this.snackBar.open( - this.getLoginErrorMessage(error as HttpErrorResponse), - 'OK', - { - duration: 5000, - }, - ); - }, - complete: () => { - this.isSubmitting = false; - this.credentialsForm.enable(); - }, - }); + this.credentialService + .requestOtk(email, password) + .pipe( + finalize(() => { + this.isSubmitting = false; + this.credentialsForm.enable(); + }), + ) + .subscribe({ + next: (otkResponse) => { + const accountId = otkResponse.account_id; + this.accountId = accountId; + this.currentStep = 'otk'; + this.otkForm.reset(); + this.startCountdown(); + this.snackBar.open( + 'OTK-Code wurde an die E-Mail-Adresse gesendet.', + 'OK', + { + duration: 4000, + }, + ); + }, + error: (error: unknown) => { + this.snackBar.open( + this.getLoginErrorMessage(error as HttpErrorResponse), + 'OK', + { + duration: 5000, + }, + ); + }, + }); } resendCode() { @@ -169,30 +173,34 @@ export class AppLoginComponent implements OnDestroy { const code = this.otkForm.controls.code.value ?? ''; - this.credentialService.loginWithOtk(this.accountId, code).subscribe({ - next: () => { - this.credentialService.reauthenticateViaIdToken().subscribe({ - next: () => { - this.checkEnter(); - this.stopCountdown(); - this.router.navigate(['/dashboard']); - }, - }); - }, - error: (error: unknown) => { - this.snackBar.open( - this.getLoginErrorMessage(error as HttpErrorResponse), - 'OK', - { - duration: 5000, - }, - ); - }, - complete: () => { - this.isSubmitting = false; - this.otkForm.enable(); - }, - }); + this.credentialService + .loginWithOtk(this.accountId, code) + .pipe( + finalize(() => { + this.isSubmitting = false; + this.otkForm.enable(); + }), + ) + .subscribe({ + next: () => { + this.credentialService.reauthenticateViaIdToken().subscribe({ + next: () => { + this.checkEnter(); + this.stopCountdown(); + this.router.navigate(['/dashboard']); + }, + }); + }, + error: (error: unknown) => { + this.snackBar.open( + this.getLoginErrorMessage(error as HttpErrorResponse), + 'OK', + { + duration: 5000, + }, + ); + }, + }); } editCredentials() {