Compare commits
No commits in common. "2fc6ba53f65ee3803b3dfd6743e472f7add01fb0" and "db394beda6934e1e710d3703d31e546a703229d9" have entirely different histories.
2fc6ba53f6
...
db394beda6
|
|
@ -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,16 @@ 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)) {
|
console.log(jwt);
|
||||||
return from(this.getAsBlob(response).text()).pipe(
|
console.log(atob(jwt));
|
||||||
tap(jwtText => {
|
this.saveJwt(atob(jwt)); //Decode jwt from base64
|
||||||
console.log('JWT from Blob:', jwtText);
|
this.isAuthenticatedSubject.next(true);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
catchError(error => {
|
catchError(error => {
|
||||||
this.snackBar.open('Login failed', '', {duration: 2000});
|
this.snackBar.open('Login failed', '', {duration: 2000});
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ UserLogin:
|
||||||
'200':
|
'200':
|
||||||
description: Logged in
|
description: Logged in
|
||||||
content:
|
content:
|
||||||
text/plain:
|
application/text:
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
description: A JWT token for this user
|
description: A JWT token for this user
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user