Skip to content

Commit a45e57e

Browse files
committed
πŸ› delete codeql workflow #1476
1 parent cfdcad1 commit a45e57e

File tree

3 files changed

+87
-103
lines changed

3 files changed

+87
-103
lines changed

β€Ž.github/workflows/codeql.ymlβ€Ž

Lines changed: 0 additions & 102 deletions
This file was deleted.

β€Žfrontend/components/auth/sessionListeners.tsxβ€Ž

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import { ExclamationCircleOutlined } from "@ant-design/icons";
88

99
import { useAuth } from "@/hooks/useAuth";
1010
import { authService } from "@/services/authService";
11+
import { sessionService } from "@/services/sessionService";
12+
import { getSessionFromStorage } from "@/lib/auth";
1113
import { EVENTS } from "@/const/auth";
14+
import {
15+
TOKEN_REFRESH_BEFORE_EXPIRY_MS,
16+
MIN_ACTIVITY_CHECK_INTERVAL_MS,
17+
} from "@/const/constants";
1218
import log from "@/lib/logger";
1319

1420
/**
@@ -129,14 +135,89 @@ export function SessionListeners() {
129135
detail: { message: "Session expired, please sign in again" },
130136
})
131137
);
138+
} else if (!session && !hadLocalSession) {
139+
// Full mode with no prior session: proactively prompt login
140+
openLoginModal();
132141
}
133142
} catch (error) {
134143
log.error("Error checking session status:", error);
135144
}
136145
};
137146

138147
checkSession();
139-
}, [pathname]);
148+
}, [pathname, isSpeedMode, openLoginModal]);
149+
150+
// Sliding expiration: refresh token shortly before expiry on user activity (skip in speed mode)
151+
useEffect(() => {
152+
if (isSpeedMode) return;
153+
154+
let lastActivityCheckAt = 0;
155+
156+
const maybeRefreshOnActivity = async () => {
157+
try {
158+
// Throttle activity-driven checks
159+
const now = Date.now();
160+
if (now - lastActivityCheckAt < MIN_ACTIVITY_CHECK_INTERVAL_MS) return;
161+
lastActivityCheckAt = now;
162+
163+
// Do not run when page is hidden
164+
if (typeof document !== "undefined" && document.hidden) return;
165+
166+
const sessionObj = getSessionFromStorage();
167+
if (!sessionObj?.expires_at) return;
168+
169+
const msUntilExpiry = sessionObj.expires_at * 1000 - now;
170+
if (msUntilExpiry <= TOKEN_REFRESH_BEFORE_EXPIRY_MS) {
171+
const ok = await sessionService.checkAndRefreshToken();
172+
if (!ok) {
173+
// If refresh failed and token is already expired, raise expired flow
174+
if (msUntilExpiry <= 0) {
175+
window.dispatchEvent(
176+
new CustomEvent(EVENTS.SESSION_EXPIRED, {
177+
detail: { message: "Session expired, please sign in again" },
178+
})
179+
);
180+
}
181+
}
182+
}
183+
} catch (error) {
184+
log.error("Activity-based refresh check failed:", error);
185+
}
186+
};
187+
188+
const events: (keyof DocumentEventMap | keyof WindowEventMap)[] = [
189+
"click",
190+
"keydown",
191+
"mousemove",
192+
"touchstart",
193+
"focus",
194+
"visibilitychange",
195+
];
196+
197+
const handler = () => {
198+
// Wrap to avoid passing the event into async function
199+
void maybeRefreshOnActivity();
200+
};
201+
202+
events.forEach((evt) => {
203+
// Use window for focus/visibility, document for input/mouse
204+
if (evt === "focus" || evt === "visibilitychange") {
205+
window.addEventListener(evt as any, handler, { passive: true });
206+
} else {
207+
document.addEventListener(evt as any, handler, { passive: true });
208+
}
209+
});
210+
211+
return () => {
212+
events.forEach((evt) => {
213+
if (evt === "focus" || evt === "visibilitychange") {
214+
window.removeEventListener(evt as any, handler as any);
215+
} else {
216+
document.removeEventListener(evt as any, handler as any);
217+
}
218+
});
219+
};
220+
}, [isSpeedMode]);
140221

141222
// This component doesn't render UI elements
142223
return null;

β€Žfrontend/const/constants.tsβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ export const languageOptions = [
55
];
66

77
export const TOKEN_REFRESH_CD = 1 * 60 * 1000;
8+
// If the remaining lifetime of the access token is below this threshold,
9+
// a refresh will be attempted on user activity (sliding expiration).
10+
export const TOKEN_REFRESH_BEFORE_EXPIRY_MS = 5 * 60 * 1000;
11+
// Throttle interval for activity-driven refresh checks
12+
export const MIN_ACTIVITY_CHECK_INTERVAL_MS = 30 * 1000;
813

914
export const isProduction = process.env.NODE_ENV === "production";
1015

0 commit comments

Comments
Β (0)