Skip to content

Commit

Permalink
refactor: skip auth-token handling on server
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi committed Apr 29, 2020
1 parent 631950d commit 89f0369
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/app/core/interceptors/auth.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isPlatformServer } from '@angular/common';
import {
HttpErrorResponse,
HttpEvent,
Expand All @@ -6,7 +7,7 @@ import {
HttpRequest,
HttpResponse,
} from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable, throwError, timer } from 'rxjs';
import { catchError, switchMapTo, tap } from 'rxjs/operators';
Expand All @@ -19,7 +20,7 @@ import { ResetAPIToken, SetAPIToken } from 'ish-core/store/user';
*/
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(private store: Store<{}>) {}
constructor(private store: Store<{}>, @Inject(PLATFORM_ID) private platformId: string) {}

private static isAuthTokenError(err: unknown) {
return (
Expand All @@ -41,6 +42,9 @@ export class AuthInterceptor implements HttpInterceptor {
}

intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
if (isPlatformServer(this.platformId)) {
return next.handle(req);
}
return next.handle(req).pipe(
// tslint:disable-next-line:ban
catchError(err => {
Expand Down

0 comments on commit 89f0369

Please sign in to comment.