UI: Fixes incorrect process error handling when updating JWT

This commit is contained in:
Vladyslav_Prykhodko 2022-11-17 16:26:45 +02:00
parent 2b74234c2c
commit a19e7f012c
3 changed files with 17 additions and 12 deletions

View File

@ -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) {

View File

@ -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}));
}));

View File

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