Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion packages/clerk-js/src/utils/__tests__/captcha.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ describe('shouldRetryTurnstileErrorCode', () => {
['104xxx', true],
['106xxx', true],
['110600', true],
['200', true],
['200100', true],
['200xxx', true],
['300xxx', true],
['600xxx', true],
['200010', false],
['100405', false],
['105001', false],
['110430', false],
Expand Down
14 changes: 11 additions & 3 deletions packages/clerk-js/src/utils/captcha/turnstile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

export const shouldRetryTurnstileErrorCode = (errorCode: string) => {
const codesWithRetries = ['crashed', 'undefined_error', '102', '103', '104', '106', '110600', '300', '600'];
const codesWithRetries = ['crashed', 'undefined_error', '102', '103', '104', '106', '110600', '200', '300', '600'];
return !!codesWithRetries.find(w => errorCode.startsWith(w));
};

Expand Down Expand Up @@ -117,7 +117,8 @@

// smart widget with container provided by user
if (!widgetContainerQuerySelector && widgetType === 'smart') {
const visibleDiv = document.getElementById(CAPTCHA_ELEMENT_ID);
// Use waitForElement to ensure the element is ready, similar to modal approach
const visibleDiv = await waitForElement(`#${CAPTCHA_ELEMENT_ID}`).catch(() => null);
if (visibleDiv) {
captchaTypeUsed = 'smart';
captchaWidgetType = 'smart';
Expand Down Expand Up @@ -147,8 +148,15 @@
}

const handleCaptchaTokenGeneration = async (): Promise<[string, string]> => {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {

Check failure on line 151 in packages/clerk-js/src/utils/captcha/turnstile.ts

View workflow job for this annotation

GitHub Actions / Static analysis

Promise executor functions should not be async
try {
// Re-verify element exists right before render to prevent 200100 errors
const containerElement = await waitForElement(widgetContainerQuerySelector);
if (!containerElement) {
reject(['Widget container element not found', undefined]);
return;
}

const id = captcha.render(widgetContainerQuerySelector, {
sitekey: turnstileSiteKey,
appearance: 'interaction-only',
Expand Down
Loading