fix: close module access lifecycle gaps

This commit is contained in:
2026-08-17 09:15:37 +08:00
parent d16922f18c
commit ebe55ba17a
8 changed files with 289 additions and 19 deletions

View File

@@ -466,7 +466,7 @@ async function handleSessionActivity(
});
}
async function handleCurrentUser(res: ServerResponse): Promise<void> {
async function handleCurrentUser(res: ServerResponse, ctx: HostApiContext): Promise<void> {
const accessToken = await getValidWorksSquareAccessToken({ forceRefresh: false });
if (!accessToken) {
sendJson(res, 401, { success: false, error: '登录已过期,请重新授权。' });
@@ -481,6 +481,13 @@ async function handleCurrentUser(res: ServerResponse): Promise<void> {
});
const payload = await readResponsePayload(response);
if (!response.ok) {
if (response.status === 401) {
clearWorksSquareSession();
await Promise.allSettled([
flushWorksSquareSessionPersistence(),
clearManagedWorksSquareRuntimeBestEffort(ctx, 'terminal current-user lookup'),
]);
}
sendJson(res, response.status === 401 ? 401 : 502, {
success: false,
error: response.status === 401
@@ -649,7 +656,7 @@ export async function handleAuthRoutes(
}
if (url.pathname === '/api/auth/me' && req.method === 'GET') {
await handleCurrentUser(res);
await handleCurrentUser(res, ctx);
return true;
}