import { Injectable } from '@angular/core'; import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor, HttpHeaders, HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Router, ActivationEnd, ActivationStart, NavigationEnd, NavigationStart, RouteConfigLoadStart } from '@angular/router'; import { environment } from 'src/environments/environment'; import { CommonService } from '../services/common.service'; @Injectable() export class LogoutInterceptor implements HttpInterceptor { public existenceEmailCheckURL = environment.adminBaseUrl + 'AdminUser/CheckEmailExistance'; public httpOptions = { headers: this.getHeader() }; constructor(router: Router, private common : CommonService) { router.events.subscribe(event => { if (event instanceof NavigationEnd) { this.common.checkUserExistence(); } }); } intercept(httpRequest: HttpRequest, next: HttpHandler): Observable> { return next.handle(httpRequest); } private getHeader(): HttpHeaders { const headers = new HttpHeaders({ 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Credentials': 'true', 'Access-Control-Allow-Headers': 'Content-Type', 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE', 'Authorization': `Bearer ${sessionStorage.getItem("token")}`, }) return headers; } }