Skip to content

Commit 9c499ea

Browse files
hhsnopekbrkalow
andauthored
feat(clerk-js): Adjust captcha parameter handling for sign ups with Google (#3806) (#3817)
Co-authored-by: Bryce Kalow <[email protected]>
1 parent 4fdafff commit 9c499ea

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

.changeset/rude-wasps-wonder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/clerk-js": patch
3+
---
4+
5+
Adjust how we pass captcha tokens to the Clerk API when signing in with Google, Microsoft, and Apple

packages/clerk-js/src/core/resources/SignUp.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ export class SignUp extends BaseResource implements SignUpResource {
7474
const { captchaSiteKey, canUseCaptcha, captchaURL, captchaWidgetType, captchaProvider, captchaPublicKeyInvisible } =
7575
retrieveCaptchaInfo(SignUp.clerk);
7676

77-
if (canUseCaptcha && captchaSiteKey && captchaURL && captchaPublicKeyInvisible) {
77+
if (
78+
!this.shouldBypassCaptchaForAttempt(params) &&
79+
canUseCaptcha &&
80+
captchaSiteKey &&
81+
captchaURL &&
82+
captchaPublicKeyInvisible
83+
) {
7884
try {
7985
const { captchaToken, captchaWidgetTypeUsed } = await getCaptchaToken({
8086
siteKey: captchaSiteKey,
@@ -94,6 +100,10 @@ export class SignUp extends BaseResource implements SignUpResource {
94100
}
95101
}
96102

103+
if (params.transfer && this.shouldBypassCaptchaForAttempt(params)) {
104+
paramsWithCaptcha.strategy = SignUp.clerk.client?.signIn.firstFactorVerification.strategy;
105+
}
106+
97107
return this._basePost({
98108
path: this.pathRoot,
99109
body: normalizeUnsafeMetadata(paramsWithCaptcha),
@@ -324,4 +334,27 @@ export class SignUp extends BaseResource implements SignUpResource {
324334
}
325335
return this;
326336
}
337+
338+
/**
339+
* We delegate bot detection to the following providers, instead of relying on turnstile exclusively
340+
*/
341+
protected shouldBypassCaptchaForAttempt(params: SignUpCreateParams) {
342+
if (
343+
params.strategy === 'oauth_google' ||
344+
params.strategy === 'oauth_microsoft' ||
345+
params.strategy === 'oauth_apple'
346+
) {
347+
return true;
348+
}
349+
if (
350+
params.transfer &&
351+
(SignUp.clerk.client?.signIn.firstFactorVerification.strategy === 'oauth_google' ||
352+
SignUp.clerk.client?.signIn.firstFactorVerification.strategy === 'oauth_microsoft' ||
353+
SignUp.clerk.client?.signIn.firstFactorVerification.strategy === 'oauth_apple')
354+
) {
355+
return true;
356+
}
357+
358+
return false;
359+
}
327360
}

0 commit comments

Comments
 (0)