forked from baron/baron-sso
front류 개발모드에서는 세션 갱신 끄기
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
export const DEFAULT_SESSION_RENEW_THRESHOLD_MS = 10 * 60 * 1000;
|
||||
export const DEFAULT_SESSION_RENEW_THROTTLE_MS = 30 * 1000;
|
||||
export const SESSION_EXPIRY_STORAGE_KEY = "baron_session_expiry_enabled";
|
||||
|
||||
type SessionExpiryReadableStorage = Pick<Storage, "getItem">;
|
||||
type SessionExpiryWritableStorage = Pick<Storage, "setItem">;
|
||||
|
||||
export type SessionRenewDecisionParams = {
|
||||
expiresAtSec?: number | null;
|
||||
@@ -13,6 +17,51 @@ export type SessionRenewDecisionParams = {
|
||||
throttleMs?: number;
|
||||
};
|
||||
|
||||
export type SessionExpiryPreferenceParams = {
|
||||
defaultEnabled?: boolean;
|
||||
storage?: SessionExpiryReadableStorage | null;
|
||||
};
|
||||
|
||||
export type DevelopmentSessionRedirectParams = {
|
||||
appMode: string;
|
||||
defaultEnabled?: boolean;
|
||||
storage?: SessionExpiryReadableStorage | null;
|
||||
};
|
||||
|
||||
function browserStorage() {
|
||||
if (typeof window === "undefined") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return window.localStorage;
|
||||
}
|
||||
|
||||
export function readSessionExpiryEnabled({
|
||||
defaultEnabled = true,
|
||||
storage = browserStorage(),
|
||||
}: SessionExpiryPreferenceParams = {}) {
|
||||
const stored = storage?.getItem(SESSION_EXPIRY_STORAGE_KEY) ?? null;
|
||||
return stored === null ? defaultEnabled : stored !== "false";
|
||||
}
|
||||
|
||||
export function writeSessionExpiryEnabled(
|
||||
isEnabled: boolean,
|
||||
storage: SessionExpiryWritableStorage | null = browserStorage(),
|
||||
) {
|
||||
storage?.setItem(SESSION_EXPIRY_STORAGE_KEY, String(isEnabled));
|
||||
}
|
||||
|
||||
export function shouldSuppressDevelopmentSessionRedirect({
|
||||
appMode,
|
||||
defaultEnabled = appMode !== "development",
|
||||
storage = browserStorage(),
|
||||
}: DevelopmentSessionRedirectParams) {
|
||||
return (
|
||||
appMode === "development" &&
|
||||
!readSessionExpiryEnabled({ defaultEnabled, storage })
|
||||
);
|
||||
}
|
||||
|
||||
function hasRenewPreconditions({
|
||||
isAuthenticated,
|
||||
isLoading,
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import {
|
||||
SESSION_EXPIRY_STORAGE_KEY,
|
||||
readSessionExpiryEnabled,
|
||||
writeSessionExpiryEnabled,
|
||||
} from "../core/session";
|
||||
|
||||
export type ShellTheme = "light" | "dark";
|
||||
|
||||
export type ShellTranslator = (
|
||||
@@ -20,8 +26,7 @@ type ShellProfileSummaryParams = {
|
||||
};
|
||||
|
||||
export const SHELL_THEME_STORAGE_KEY = "admin_theme";
|
||||
export const SHELL_SESSION_EXPIRY_STORAGE_KEY =
|
||||
"baron_session_expiry_enabled";
|
||||
export const SHELL_SESSION_EXPIRY_STORAGE_KEY = SESSION_EXPIRY_STORAGE_KEY;
|
||||
export { AppSidebar } from "./AppSidebar";
|
||||
export type { ShellSidebarNavItem } from "./AppSidebar";
|
||||
export { shellLayoutClasses } from "./layout";
|
||||
@@ -39,15 +44,12 @@ export function applyShellTheme(theme: ShellTheme) {
|
||||
window.localStorage.setItem(SHELL_THEME_STORAGE_KEY, theme);
|
||||
}
|
||||
|
||||
export function readShellSessionExpiryEnabled() {
|
||||
return window.localStorage.getItem(SHELL_SESSION_EXPIRY_STORAGE_KEY) !== "false";
|
||||
export function readShellSessionExpiryEnabled(defaultEnabled = true) {
|
||||
return readSessionExpiryEnabled({ defaultEnabled });
|
||||
}
|
||||
|
||||
export function writeShellSessionExpiryEnabled(isEnabled: boolean) {
|
||||
window.localStorage.setItem(
|
||||
SHELL_SESSION_EXPIRY_STORAGE_KEY,
|
||||
String(isEnabled),
|
||||
);
|
||||
writeSessionExpiryEnabled(isEnabled);
|
||||
}
|
||||
|
||||
export function buildShellProfileSummary({
|
||||
|
||||
Reference in New Issue
Block a user