mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-11 13:29:12 +00:00
Address greptile comments
This commit is contained in:
@@ -45,6 +45,10 @@ apiRequest.interceptors.request.use((config) => {
|
|||||||
|
|
||||||
let isRedirecting = false;
|
let isRedirecting = false;
|
||||||
|
|
||||||
|
const resetRedirectingFlag = () => {
|
||||||
|
isRedirecting = false;
|
||||||
|
};
|
||||||
|
|
||||||
apiRequest.interceptors.response.use(
|
apiRequest.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
async (error) => {
|
async (error) => {
|
||||||
@@ -58,17 +62,20 @@ apiRequest.interceptors.response.use(
|
|||||||
// Check if the error indicates token expiration
|
// Check if the error indicates token expiration
|
||||||
const errorMessage = response.data?.message || "";
|
const errorMessage = response.data?.message || "";
|
||||||
const isTokenExpired =
|
const isTokenExpired =
|
||||||
response.status === 401 ||
|
errorMessage.toLowerCase().includes("token") &&
|
||||||
(errorMessage.toLowerCase().includes("token") &&
|
|
||||||
(errorMessage.toLowerCase().includes("expired") ||
|
(errorMessage.toLowerCase().includes("expired") ||
|
||||||
errorMessage.toLowerCase().includes("invalid") ||
|
errorMessage.toLowerCase().includes("invalid") ||
|
||||||
errorMessage.toLowerCase().includes("unauthorized")));
|
errorMessage.toLowerCase().includes("unauthorized"));
|
||||||
|
|
||||||
if (isTokenExpired) {
|
if (isTokenExpired) {
|
||||||
isRedirecting = true;
|
isRedirecting = true;
|
||||||
|
|
||||||
|
try {
|
||||||
setAuthToken("");
|
setAuthToken("");
|
||||||
SecurityClient.setToken("");
|
SecurityClient.setToken("");
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("Error clearing tokens:", err);
|
||||||
|
}
|
||||||
|
|
||||||
createNotification({
|
createNotification({
|
||||||
type: "error",
|
type: "error",
|
||||||
@@ -76,6 +83,7 @@ apiRequest.interceptors.response.use(
|
|||||||
text: "Your session has expired. Redirecting to login page..."
|
text: "Your session has expired. Redirecting to login page..."
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
sessionStorage.setItem(
|
sessionStorage.setItem(
|
||||||
SessionStorageKeys.ORG_LOGIN_SUCCESS_REDIRECT_URL,
|
SessionStorageKeys.ORG_LOGIN_SUCCESS_REDIRECT_URL,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -83,10 +91,15 @@ apiRequest.interceptors.response.use(
|
|||||||
data: window.location.href
|
data: window.location.href
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("Could not save redirect URL to sessionStorage:", err);
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = "/login";
|
window.location.href = "/login";
|
||||||
}, 5000); // 5 seconds to read the notification
|
}, 2000); // 2 seconds to read the notification
|
||||||
|
|
||||||
|
setTimeout(resetRedirectingFlag, 3000);
|
||||||
|
|
||||||
return Promise.reject(new Error("Session expired - redirecting to login"));
|
return Promise.reject(new Error("Session expired - redirecting to login"));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user