Move to new server
This commit is contained in:
27
src/app/authentication/tokenInterceptor.ts
Normal file
27
src/app/authentication/tokenInterceptor.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import {Injectable} from "@angular/core";
|
||||
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
|
||||
import {Observable} from "rxjs";
|
||||
import {UserService} from "./user.service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TokenInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private userService: UserService) { }
|
||||
|
||||
intercept(
|
||||
request: HttpRequest<any>,
|
||||
next: HttpHandler
|
||||
): Observable<HttpEvent<any>> {
|
||||
if (this.userService.isLoggedIn()) {
|
||||
let newRequest = request.clone({
|
||||
setHeaders: {
|
||||
Authorization: `Bearer ${this.userService.getUser()?.accessToken}`,
|
||||
},
|
||||
});
|
||||
return next.handle(newRequest);
|
||||
}
|
||||
return next.handle(request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user