Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class JwtRefreshInterceptor implements HttpInterceptor {
- public constructor(
- private httpClient: HttpClient,
- ) { }
- intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
- return next.handle(request).catch((error: HttpErrorResponse) => {
- if (error.status === 401) {
- return this.httpClient.post(environment.base_uri + 'auth/refresh', {}).flatMap((response) => {
- // get token from response.
- // put token in localstorage.
- // add token to the request.
- // Do the request again with the new token.
- return next.handle(request);
- });
- }
- return Observable.throw(error);
- });
- }
- }
- Provider parse errors:
- Cannot instantiate cyclic dependency! InjectionToken_HTTP_INTERCEPTORS ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1
Add Comment
Please, Sign In to add comment