Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Router } from '@angular/router';
import 'rxjs/add/operator/do';
@Injectable()
export class UnauthorizedRedirectInterceptor implements HttpInterceptor {
constructor(private router: Router) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (req.headers.get('Auth') === 'false') {
return next.handle(req);
}
const clonedReq = req.clone({withCredentials: true});
return next.handle(clonedReq).do(event => {}, err => {
if (err instanceof HttpErrorResponse && err.status === 401) {
sessionStorage.clear();
this.router.navigate(['/']);
}
});
}
}