|
|
@ -4,6 +4,7 @@ import { AuthService } from '../services/auth.service';
|
|
|
|
import { Observable, throwError, BehaviorSubject } from 'rxjs';
|
|
|
|
import { Observable, throwError, BehaviorSubject } from 'rxjs';
|
|
|
|
import { catchError, filter, take, switchMap } from 'rxjs/operators';
|
|
|
|
import { catchError, filter, take, switchMap } from 'rxjs/operators';
|
|
|
|
import { SnackBarService } from '../services/snackbar.service';
|
|
|
|
import { SnackBarService } from '../services/snackbar.service';
|
|
|
|
|
|
|
|
import { Router, RouterStateSnapshot } from '@angular/router';
|
|
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
@Injectable()
|
|
|
|
export class TokenInterceptor implements HttpInterceptor {
|
|
|
|
export class TokenInterceptor implements HttpInterceptor {
|
|
|
@ -11,7 +12,7 @@ export class TokenInterceptor implements HttpInterceptor {
|
|
|
|
private isRefreshing = false;
|
|
|
|
private isRefreshing = false;
|
|
|
|
private requestTokenSubject: BehaviorSubject<any> = new BehaviorSubject<any>(null);
|
|
|
|
private requestTokenSubject: BehaviorSubject<any> = new BehaviorSubject<any>(null);
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private authService: AuthService, private snackBar : SnackBarService) { }
|
|
|
|
constructor(private authService: AuthService, private snackBar : SnackBarService, private router: Router) { }
|
|
|
|
|
|
|
|
|
|
|
|
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
|
|
|
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
|
|
|
|
|
|
|
|
|
|
@ -27,8 +28,11 @@ export class TokenInterceptor implements HttpInterceptor {
|
|
|
|
errorMessage = `Error: ${error.error.message}`;
|
|
|
|
errorMessage = `Error: ${error.error.message}`;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//server error
|
|
|
|
//server error
|
|
|
|
|
|
|
|
if (error.status === 400){
|
|
|
|
if (error.status === 401) {
|
|
|
|
this.authService.logout();
|
|
|
|
|
|
|
|
errorMessage = "Die aktuelle Sitzung ist abgelaufen. Bitte loggen sie sich erneut ein."
|
|
|
|
|
|
|
|
this.router.navigate(["/login"], { queryParams: { returnUrl: this.router.routerState.snapshot.url } });
|
|
|
|
|
|
|
|
} else if (error.status === 401) {
|
|
|
|
var urlSplit : string[] = error.url.split("/");
|
|
|
|
var urlSplit : string[] = error.url.split("/");
|
|
|
|
if (urlSplit[3] === "users" && urlSplit[5] === "update"){ // Allow user pw updates to be processed correctly
|
|
|
|
if (urlSplit[3] === "users" && urlSplit[5] === "update"){ // Allow user pw updates to be processed correctly
|
|
|
|
errorMessage = "Das aktuelle Passwort ist inkorrekt.";
|
|
|
|
errorMessage = "Das aktuelle Passwort ist inkorrekt.";
|
|
|
|