feat: add TTL to GameSessionStore, replay protection and session cleanup to evaluateAnswer

This commit is contained in:
lila 2026-04-28 14:03:15 +02:00
parent 54705943fa
commit fdeb769640
6 changed files with 218 additions and 7 deletions

View file

@ -59,7 +59,7 @@ export const createGameSession = async (
);
const sessionId = randomUUID();
await store.create(sessionId, { answers: answerKey });
await store.create(sessionId, { answers: answerKey }, 30 * 60 * 1000);
return { sessionId, questions };
};
@ -80,6 +80,12 @@ export const evaluateAnswer = async (
throw new NotFoundError(`Question not found: ${submission.questionId}`);
}
session.answers.delete(submission.questionId);
if (session.answers.size === 0) {
await store.delete(submission.sessionId);
}
return {
questionId: submission.questionId,
isCorrect: submission.selectedOptionId === correctOptionId,