Browse Source
Merge pull request #7637 from vvlladd28/bug/catch-error/refresh-token
[3.4.2] UI: Fixes incorrect process error handling when updating JWT
pull/7646/head
Igor Kulikov
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
17 additions and
12 deletions
-
ui-ngx/src/app/core/auth/auth.service.ts
-
ui-ngx/src/app/core/interceptors/global-http-interceptor.ts
-
ui-ngx/src/app/core/ws/telemetry-websocket.service.ts
|
|
|
@ -195,18 +195,22 @@ export class AuthService { |
|
|
|
)); |
|
|
|
} |
|
|
|
|
|
|
|
public logout(captureLastUrl: boolean = false) { |
|
|
|
public logout(captureLastUrl: boolean = false, ignoreRequest = false) { |
|
|
|
if (captureLastUrl) { |
|
|
|
this.redirectUrl = this.router.url; |
|
|
|
} |
|
|
|
this.http.post('/api/auth/logout', null, defaultHttpOptions(true, true)) |
|
|
|
.subscribe(() => { |
|
|
|
this.clearJwtToken(); |
|
|
|
}, |
|
|
|
() => { |
|
|
|
this.clearJwtToken(); |
|
|
|
} |
|
|
|
); |
|
|
|
if (!ignoreRequest) { |
|
|
|
this.http.post('/api/auth/logout', null, defaultHttpOptions(true, true)) |
|
|
|
.subscribe(() => { |
|
|
|
this.clearJwtToken(); |
|
|
|
}, |
|
|
|
() => { |
|
|
|
this.clearJwtToken(); |
|
|
|
} |
|
|
|
); |
|
|
|
} else { |
|
|
|
this.clearJwtToken(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private notifyUserLoaded(isUserLoaded: boolean) { |
|
|
|
|
|
|
|
@ -103,7 +103,8 @@ export class GlobalHttpInterceptor implements HttpInterceptor { |
|
|
|
const ignoreErrors = config.ignoreErrors; |
|
|
|
const resendRequest = config.resendRequest; |
|
|
|
const errorCode = errorResponse.error ? errorResponse.error.errorCode : null; |
|
|
|
if (errorResponse.error && errorResponse.error.refreshTokenPending || errorResponse.status === 401) { |
|
|
|
if (errorResponse.error && errorResponse.error.refreshTokenPending || |
|
|
|
errorResponse.status === 401 && req.url !== Constants.entryPoints.tokenRefresh) { |
|
|
|
if (errorResponse.error && errorResponse.error.refreshTokenPending || |
|
|
|
errorCode && errorCode === Constants.serverErrorCode.jwtTokenExpired) { |
|
|
|
return this.refreshTokenAndRetry(req, next); |
|
|
|
@ -153,7 +154,7 @@ export class GlobalHttpInterceptor implements HttpInterceptor { |
|
|
|
return this.jwtIntercept(req, next); |
|
|
|
}), |
|
|
|
catchError((err: Error) => { |
|
|
|
this.authService.logout(true); |
|
|
|
this.authService.logout(true, true); |
|
|
|
const message = err ? err.message : 'Unauthorized!'; |
|
|
|
return this.handleResponseError(req, next, new HttpErrorResponse({error: {message, timeout: 200}, status: 401})); |
|
|
|
})); |
|
|
|
|
|
|
|
@ -233,7 +233,7 @@ export class TelemetryWebsocketService implements TelemetryService { |
|
|
|
}, |
|
|
|
() => { |
|
|
|
this.isOpening = false; |
|
|
|
this.authService.logout(true); |
|
|
|
this.authService.logout(true, true); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
|