src/app/shared/helpers/jwt.interceptor.ts
Methods |
constructor(authenticationService: AuthService)
|
||||||
|
Defined in src/app/shared/helpers/jwt.interceptor.ts:7
|
||||||
|
Parameters :
|
| intercept | |||||||||
intercept(request: HttpRequest
|
|||||||||
|
Defined in src/app/shared/helpers/jwt.interceptor.ts:11
|
|||||||||
|
Parameters :
Returns :
Observable<HttpEvent<any>>
|
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Observable } from 'rxjs';
import {AuthService} from '@app/auth/services/auth.service';
@Injectable()
export class JwtInterceptor implements HttpInterceptor {
constructor(private authenticationService: AuthService) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const currentUser = this.authenticationService.currentUserValue;
const isLoggedIn = currentUser && currentUser.access_token;
if (isLoggedIn) {
request = request.clone({
setHeaders: {
Authorization: `Bearer ${currentUser.access_token}`
}
});
}
return next.handle(request);
}
}