fix(login): re-enable forms after failed auth requests
LocationBasedServices/smartguide/pipeline/head There was a failure building this commit
LocationBasedServices/smartguide/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user