Remove Blob handling logic from AuthService.login and simplify JWT processing.

This commit is contained in:
akastijn 2025-07-06 21:00:52 +02:00
parent 2fc6ba53f6
commit ace969ba3b

View File

@ -1,6 +1,6 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {LoginService} from '@api'; 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 {catchError, tap} from 'rxjs/operators';
import {MatSnackBar} from '@angular/material/snack-bar'; import {MatSnackBar} from '@angular/material/snack-bar';
import {JwtHelperService} from '@auth0/angular-jwt'; import {JwtHelperService} from '@auth0/angular-jwt';
@ -25,34 +25,14 @@ export class AuthService {
this.checkAuthStatus(); 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 * Attempt to login with the provided code
*/ */
public login(code: string): Observable<any> { public login(code: string): Observable<any> {
return this.loginService.login(code).pipe( return this.loginService.login(code).pipe(
switchMap(response => { tap(jwt => {
if (this.isBlob(response)) { this.saveJwt(jwt);
return from(this.getAsBlob(response).text()).pipe(
tap(jwtText => {
console.log('JWT from Blob:', jwtText);
this.saveJwt(jwtText);
this.isAuthenticatedSubject.next(true); this.isAuthenticatedSubject.next(true);
})
);
} else {
console.log('JWT as string:', response);
this.saveJwt(atob(response));
this.isAuthenticatedSubject.next(true);
return of(response);
}
}), }),
catchError(error => { catchError(error => {
this.snackBar.open('Login failed', '', {duration: 2000}); this.snackBar.open('Login failed', '', {duration: 2000});