Remove Blob handling logic from AuthService.login and simplify JWT processing.
This commit is contained in:
parent
2fc6ba53f6
commit
ace969ba3b
|
|
@ -1,6 +1,6 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {LoginService} from '@api';
|
||||
import {BehaviorSubject, from, Observable, of, switchMap, throwError} from 'rxjs';
|
||||
import {BehaviorSubject, Observable, throwError} from 'rxjs';
|
||||
import {catchError, tap} from 'rxjs/operators';
|
||||
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||
import {JwtHelperService} from '@auth0/angular-jwt';
|
||||
|
|
@ -25,34 +25,14 @@ export class AuthService {
|
|||
this.checkAuthStatus();
|
||||
}
|
||||
|
||||
private isBlob(value: any): boolean {
|
||||
return value instanceof Blob;
|
||||
}
|
||||
|
||||
private getAsBlob(value: any): Blob {
|
||||
return value as Blob;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to login with the provided code
|
||||
*/
|
||||
public login(code: string): Observable<any> {
|
||||
return this.loginService.login(code).pipe(
|
||||
switchMap(response => {
|
||||
if (this.isBlob(response)) {
|
||||
return from(this.getAsBlob(response).text()).pipe(
|
||||
tap(jwtText => {
|
||||
console.log('JWT from Blob:', jwtText);
|
||||
this.saveJwt(jwtText);
|
||||
this.isAuthenticatedSubject.next(true);
|
||||
})
|
||||
);
|
||||
} else {
|
||||
console.log('JWT as string:', response);
|
||||
this.saveJwt(atob(response));
|
||||
this.isAuthenticatedSubject.next(true);
|
||||
return of(response);
|
||||
}
|
||||
tap(jwt => {
|
||||
this.saveJwt(jwt);
|
||||
this.isAuthenticatedSubject.next(true);
|
||||
}),
|
||||
catchError(error => {
|
||||
this.snackBar.open('Login failed', '', {duration: 2000});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user