Skip to content

Commit

Permalink
reset turnstile widget on server errors
Browse files Browse the repository at this point in the history
  • Loading branch information
soof-golan committed Oct 28, 2024
1 parent 4a01db6 commit 26fa6ad
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion website/components/WaitingRoomForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ type WaitingRoomProps = {

type FormInput = Omit<RegisterInput, "waitingRoomId">;

// Reset CloudFlare Turnstile widget state to allow legitimate re-submission
function resetTurnstile() {
// @ts-expect-error: turnstile exists on window.
window.turnstile.reset();
}

const noEventChoice = "";

export default function WaitingRoomForm({
Expand All @@ -32,7 +38,7 @@ export default function WaitingRoomForm({
}: WaitingRoomProps) {
const [now, setNow] = useState(moment());
const [token] = useTurnstile();
const registerApi = trpc.register.useMutation();
const registerApi = trpc.register.useMutation({ onError: resetTurnstile });
const eventChoicesArr = eventChoices
.trim()
.split(",")
Expand Down

0 comments on commit 26fa6ad

Please sign in to comment.