fix(auth): revoke stale sessions and tokens

Revoked or rotated credentials must stop working despite stale KV
replicas. Track the live token and revocations in D1 and preserve
immutable identity bindings rather than trusting a recycled login.
This commit is contained in:
翅膀 committed 2026-10-23 23:22:52 +08:00
1 parent 5ff2338b48
commit 2bdce90776
5 files changed
+285 -22

No files matched your search

+2 -1
View File
@@ -99,7 +99,8 @@ export async function bearerUserId(event: H3Event): Promise<string> {
const auth = getHeader(event, "authorization");
if (!auth?.startsWith("Bearer "))
throw createError({ statusCode: 401, statusMessage: "Missing authorization" });
const userId = await findUserIdByToken(env.KV, auth.slice(7));
// Resolves only the user's *current* token: a rotated or revoked one fails.
const userId = await findUserIdByToken(env.KV, auth.slice(7), env.DB);
if (!userId) throw createError({ statusCode: 401, statusMessage: "Invalid or expired token" });
return userId;
}