Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/hooks/use-verify-answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type UseVerifyAnswerOptions = {
onFinish?: (data: VerifyAnswerResponse) => void;
};

const MAX_QUIZ_QUESTION_LENGTH = 500;

export function useVerifyAnswer(options: UseVerifyAnswerOptions) {
const { quizSlug, question, userAnswer, onError, onFinish } = options;

Expand All @@ -36,14 +38,19 @@ export function useVerifyAnswer(options: UseVerifyAnswerOptions) {
abortControllerRef.current?.abort();
abortControllerRef.current = new AbortController();

const safeQuestion =
question.length > MAX_QUIZ_QUESTION_LENGTH
? question.slice(0, MAX_QUIZ_QUESTION_LENGTH)
: question;

const response = await fetch(
`${import.meta.env.PUBLIC_API_URL}/v1-verify-quiz-answer/${quizSlug}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ question, userAnswer }),
body: JSON.stringify({ question: safeQuestion, userAnswer }),
signal: abortControllerRef.current?.signal,
credentials: 'include',
},
Expand Down