Update about the showing the user images
This commit is contained in:
@@ -19,21 +19,17 @@ export class CachingInterceptor implements HttpInterceptor {
|
||||
|
||||
intercept(req: HttpRequest<any>, next: HttpHandler) {
|
||||
const cachedResponse = this.cache.get(req);
|
||||
return cachedResponse
|
||||
? Observable.of(cachedResponse)
|
||||
: this.sendRequest(req, next);
|
||||
return cachedResponse ? Observable.of(cachedResponse) : this.sendRequest(req, next);
|
||||
}
|
||||
|
||||
sendRequest(
|
||||
req: HttpRequest<any>,
|
||||
next: HttpHandler
|
||||
): Observable<HttpEvent<any>> {
|
||||
return next.handle(req).pipe(
|
||||
tap(event => {
|
||||
if (event instanceof HttpResponse) {
|
||||
this.cache.put(req, event);
|
||||
}
|
||||
})
|
||||
sendRequest(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
return next.handle(req)
|
||||
.pipe(
|
||||
tap(event => {
|
||||
if (event instanceof HttpResponse) {
|
||||
this.cache.put(req, event);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,20 +5,25 @@ import { catchError } from 'rxjs/operators';
|
||||
|
||||
import { AuthenticationService } from '../services/authentication.service';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ErrorInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private authenticationService: AuthenticationService) { }
|
||||
|
||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
return next.handle(request).pipe(catchError(err => {
|
||||
if (err.status === 401) {
|
||||
// auto logout if 401 response returned from api
|
||||
this.authenticationService.logout();
|
||||
location.reload(true);
|
||||
}
|
||||
return next.handle(request)
|
||||
.pipe(
|
||||
catchError(err => {
|
||||
if (err.status === 401) {
|
||||
// auto logout if 401 response returned from api
|
||||
this.authenticationService.logout();
|
||||
location.reload();
|
||||
}
|
||||
|
||||
const error = err.error.message || err.statusText;
|
||||
return throwError(error);
|
||||
}));
|
||||
const error = err.error.message || err.statusText;
|
||||
return throwError(error);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import {
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
} from "@angular/common/http";
|
||||
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from "@angular/common/http";
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import { AuthenticationService } from "../services/authentication.service";
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class JwtAuthInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private authenticationService: AuthenticationService) {}
|
||||
|
||||
intercept(
|
||||
request: HttpRequest<any>,
|
||||
next: HttpHandler
|
||||
): Observable<HttpEvent<any>> {
|
||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
// add authorization header with basic auth credentials if available
|
||||
const currentUser = this.authenticationService.currentUserValue;
|
||||
|
||||
if (currentUser && currentUser.token) {
|
||||
request = request.clone({
|
||||
setHeaders: {
|
||||
|
||||
Reference in New Issue
Block a user