core: do a healthcheck before logging out user on session revoke

This commit is contained in:
Abdullah Atta
2023-03-17 17:00:15 +05:00
committed by Abdullah Atta
parent 1ee24cde07
commit 3674594832
2 changed files with 43 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ import http from "../utils/http";
import constants from "../utils/constants";
import TokenManager from "./token-manager";
import { EV, EVENTS } from "../common";
import { HealthCheck } from "./healthcheck";
const ENDPOINTS = {
signup: "/users",
@@ -48,14 +49,20 @@ class UserManager {
this.tokenManager = new TokenManager(storage);
EV.subscribe(EVENTS.userUnauthorized, async (url) => {
if (url.includes("/connect/token")) return;
if (
url.includes("/connect/token") ||
!(await HealthCheck.isAuthServerHealthy())
)
return;
try {
await this.tokenManager._refreshToken(true);
} catch (e) {
await this.logout(
false,
`Your token has been revoked. Error: ${e.message}.`
);
if (e.message === "invalid_grant" || e.message === "invalid_client") {
await this.logout(
false,
`Your token has been revoked. Error: ${e.message}.`
);
}
}
});
}