Merge pull request #7637 from vvlladd28/bug/catch-error/refresh-token

[3.4.2] UI: Fixes incorrect process error handling when updating JWT
This commit is contained in:
Igor Kulikov 2022-11-17 17:11:12 +02:00 committed by GitHub
commit 8a2fe097ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 12 deletions

View File

@ -195,10 +195,11 @@ export class AuthService {
)); ));
} }
public logout(captureLastUrl: boolean = false) { public logout(captureLastUrl: boolean = false, ignoreRequest = false) {
if (captureLastUrl) { if (captureLastUrl) {
this.redirectUrl = this.router.url; this.redirectUrl = this.router.url;
} }
if (!ignoreRequest) {
this.http.post('/api/auth/logout', null, defaultHttpOptions(true, true)) this.http.post('/api/auth/logout', null, defaultHttpOptions(true, true))
.subscribe(() => { .subscribe(() => {
this.clearJwtToken(); this.clearJwtToken();
@ -207,6 +208,9 @@ export class AuthService {
this.clearJwtToken(); this.clearJwtToken();
} }
); );
} else {
this.clearJwtToken();
}
} }
private notifyUserLoaded(isUserLoaded: boolean) { private notifyUserLoaded(isUserLoaded: boolean) {

View File

@ -103,7 +103,8 @@ export class GlobalHttpInterceptor implements HttpInterceptor {
const ignoreErrors = config.ignoreErrors; const ignoreErrors = config.ignoreErrors;
const resendRequest = config.resendRequest; const resendRequest = config.resendRequest;
const errorCode = errorResponse.error ? errorResponse.error.errorCode : null; 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 || if (errorResponse.error && errorResponse.error.refreshTokenPending ||
errorCode && errorCode === Constants.serverErrorCode.jwtTokenExpired) { errorCode && errorCode === Constants.serverErrorCode.jwtTokenExpired) {
return this.refreshTokenAndRetry(req, next); return this.refreshTokenAndRetry(req, next);
@ -153,7 +154,7 @@ export class GlobalHttpInterceptor implements HttpInterceptor {
return this.jwtIntercept(req, next); return this.jwtIntercept(req, next);
}), }),
catchError((err: Error) => { catchError((err: Error) => {
this.authService.logout(true); this.authService.logout(true, true);
const message = err ? err.message : 'Unauthorized!'; const message = err ? err.message : 'Unauthorized!';
return this.handleResponseError(req, next, new HttpErrorResponse({error: {message, timeout: 200}, status: 401})); return this.handleResponseError(req, next, new HttpErrorResponse({error: {message, timeout: 200}, status: 401}));
})); }));

View File

@ -233,7 +233,7 @@ export class TelemetryWebsocketService implements TelemetryService {
}, },
() => { () => {
this.isOpening = false; this.isOpening = false;
this.authService.logout(true); this.authService.logout(true, true);
} }
); );
} }