X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-main%2Fauth%2Fauth-interceptor.service.ts;h=93b3a93d6d4255def5a42c0f606353c05fb98f96;hb=d0fbc9fd0a29c37f3ff9b99030351e90b276fe7d;hp=a75c8a25c7c29b3dd797829c50f6ad4011b5c0c2;hpb=a24bd1ed41b43790bab6ba789580bb4e85f07d85;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts b/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts index a75c8a25c..93b3a93d6 100644 --- a/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts +++ b/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts @@ -27,16 +27,19 @@ export class AuthInterceptor implements HttpInterceptor { .pipe( catchError((err: HttpErrorResponse) => { const error = err.error as PeerTubeProblemDocument + const isOTPMissingError = this.authService.isOTPMissingError(err) - if (err.status === HttpStatusCode.UNAUTHORIZED_401 && error && error.code === OAuth2ErrorCode.INVALID_TOKEN) { - return this.handleTokenExpired(req, next) - } + if (!isOTPMissingError) { + if (err.status === HttpStatusCode.UNAUTHORIZED_401 && error && error.code === OAuth2ErrorCode.INVALID_TOKEN) { + return this.handleTokenExpired(req, next) + } - if (err.status === HttpStatusCode.UNAUTHORIZED_401) { - return this.handleNotAuthenticated(err) + if (err.status === HttpStatusCode.UNAUTHORIZED_401) { + return this.handleNotAuthenticated(err) + } } - return observableThrowError(err) + return observableThrowError(() => err) }) ) } @@ -61,8 +64,8 @@ export class AuthInterceptor implements HttpInterceptor { return req.clone({ headers: req.headers.set('Authorization', authHeaderValue) }) } - private handleNotAuthenticated (err: HttpErrorResponse, path = '/login'): Observable { - this.router.navigateByUrl(path) + private handleNotAuthenticated (err: HttpErrorResponse): Observable { + this.router.navigate([ '/401' ], { state: { obj: err }, skipLocationChange: true }) return of(err.message) } }