-
Notifications
You must be signed in to change notification settings - Fork 0
/
license.interceptors.ts
30 lines (26 loc) · 1 KB
/
license.interceptors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { Router } from "@angular/router";
import { map } from "rxjs/operators";
import { CookieService } from "ngx-cookie-service";
@Injectable()
export class LicenseInterceptor implements HttpInterceptor {
constructor(
protected router: Router,
protected cookieService: CookieService
) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const cloned = req.clone({ withCredentials: true });
return next.handle(cloned)
.pipe(map((event: any) => {
const cookieExists: boolean = this.cookieService.check('X-Licensed');
if (!cookieExists) {
console.error("Invalid license!");
console.error("Navigating to error page!");
this.router.navigate(["invalid-license"]).then();
}
return event;
}));
}
}