forked from baron/baron-sso
front류 개발모드에서는 세션 갱신 끄기
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import axios from "axios";
|
||||
import { shouldStartLoginRedirect } from "../../../common/core/auth";
|
||||
import {
|
||||
shouldSuppressDevelopmentSessionRedirect,
|
||||
} from "../../../common/core/session";
|
||||
import { userManager } from "./auth";
|
||||
|
||||
let isRedirectingToLogin = false;
|
||||
@@ -42,6 +45,17 @@ apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error) => {
|
||||
if (error.response?.status === 401) {
|
||||
if (
|
||||
shouldSuppressDevelopmentSessionRedirect({
|
||||
appMode: import.meta.env.MODE,
|
||||
})
|
||||
) {
|
||||
console.warn(
|
||||
"[apiClient] 401 Unauthorized detected, but development session redirects are disabled.",
|
||||
);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
console.warn(
|
||||
"[apiClient] 401 Unauthorized detected. Clearing session state.",
|
||||
);
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
readSessionExpiryEnabled,
|
||||
SESSION_RENEW_THRESHOLD_MS,
|
||||
shouldAttemptSlidingSessionRenew,
|
||||
shouldSuppressDevelopmentSessionRedirect,
|
||||
shouldAttemptUnlimitedSessionRenew,
|
||||
writeSessionExpiryEnabled,
|
||||
} from "./sessionSliding";
|
||||
|
||||
function memoryStorage(initialValue: string | null = null) {
|
||||
let value = initialValue;
|
||||
return {
|
||||
getItem: (_key: string) => value,
|
||||
setItem: (_key: string, nextValue: string) => {
|
||||
value = nextValue;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("shouldAttemptSlidingSessionRenew", () => {
|
||||
const nowMs = 1_700_000_000_000;
|
||||
|
||||
@@ -124,3 +137,43 @@ describe("shouldAttemptUnlimitedSessionRenew", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("session expiry development preference", () => {
|
||||
it("defaults session expiry management off in development when no preference is stored", () => {
|
||||
expect(
|
||||
readSessionExpiryEnabled({
|
||||
defaultEnabled: false,
|
||||
storage: memoryStorage(null),
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps explicit stored preference over the development default", () => {
|
||||
const storage = memoryStorage(null);
|
||||
|
||||
writeSessionExpiryEnabled(true, storage);
|
||||
|
||||
expect(
|
||||
readSessionExpiryEnabled({
|
||||
defaultEnabled: false,
|
||||
storage,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("suppresses login redirects only in development with disabled session expiry management", () => {
|
||||
expect(
|
||||
shouldSuppressDevelopmentSessionRedirect({
|
||||
appMode: "development",
|
||||
storage: memoryStorage(null),
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
shouldSuppressDevelopmentSessionRedirect({
|
||||
appMode: "production",
|
||||
storage: memoryStorage(null),
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
export {
|
||||
DEFAULT_SESSION_RENEW_THROTTLE_MS as SESSION_RENEW_THROTTLE_MS,
|
||||
DEFAULT_SESSION_RENEW_THRESHOLD_MS as SESSION_RENEW_THRESHOLD_MS,
|
||||
readSessionExpiryEnabled,
|
||||
shouldAttemptSlidingSessionRenew,
|
||||
shouldSuppressDevelopmentSessionRedirect,
|
||||
shouldAttemptUnlimitedSessionRenew,
|
||||
writeSessionExpiryEnabled,
|
||||
} from "../../../common/core/session";
|
||||
|
||||
Reference in New Issue
Block a user