feat: add TTL to GameSessionStore, replay protection and session cleanup to evaluateAnswer
This commit is contained in:
parent
54705943fa
commit
fdeb769640
6 changed files with 218 additions and 7 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue