src/app/auth/support/token.interceptor.ts
Methods |
constructor(inj: Injector)
|
||||||||
Defined in src/app/auth/support/token.interceptor.ts:7
|
||||||||
Parameters :
|
intercept | ||||||||||||
intercept(request: HttpRequest
|
||||||||||||
Defined in src/app/auth/support/token.interceptor.ts:12
|
||||||||||||
Parameters :
Returns :
Observable<HttpEvent<any>>
|
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Injectable, Injector } from '@angular/core';
import { Observable } from 'rxjs';
import { AuthService } from '../auth.service';
@Injectable()
export class TokenInterceptor implements HttpInterceptor {
constructor(private inj: Injector) {
}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const auth = this.inj.get(AuthService);
if (auth.xAuthToken) {
request = request.clone({
setHeaders: {
'x-auth-token': `${auth.xAuthToken}`
}
});
}
return next.handle(request);
}
}