Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/rude-wasps-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/clerk-js": patch
---

Adjust how we pass captcha tokens to the Clerk API when signing in with Google, Microsoft, and Apple
35 changes: 34 additions & 1 deletion packages/clerk-js/src/core/resources/SignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ export class SignUp extends BaseResource implements SignUpResource {
const { captchaSiteKey, canUseCaptcha, captchaURL, captchaWidgetType, captchaProvider, captchaPublicKeyInvisible } =
retrieveCaptchaInfo(SignUp.clerk);

if (canUseCaptcha && captchaSiteKey && captchaURL && captchaPublicKeyInvisible) {
if (
!this.shouldBypassCaptchaForAttempt(params) &&
canUseCaptcha &&
captchaSiteKey &&
captchaURL &&
captchaPublicKeyInvisible
) {
try {
const { captchaToken, captchaWidgetTypeUsed } = await getCaptchaToken({
siteKey: captchaSiteKey,
Expand All @@ -91,6 +97,10 @@ export class SignUp extends BaseResource implements SignUpResource {
}
}

if (params.transfer && this.shouldBypassCaptchaForAttempt(params)) {
paramsWithCaptcha.strategy = SignUp.clerk.client?.signIn.firstFactorVerification.strategy;
}

return this._basePost({
path: this.pathRoot,
body: normalizeUnsafeMetadata(paramsWithCaptcha),
Expand Down Expand Up @@ -264,4 +274,27 @@ export class SignUp extends BaseResource implements SignUpResource {
}
return this;
}

/**
* We delegate bot detection to the following providers, instead of relying on turnstile exclusively
*/
protected shouldBypassCaptchaForAttempt(params: SignUpCreateParams) {
if (
params.strategy === 'oauth_google' ||
params.strategy === 'oauth_microsoft' ||
params.strategy === 'oauth_apple'
) {
return true;
}
if (
params.transfer &&
(SignUp.clerk.client?.signIn.firstFactorVerification.strategy === 'oauth_google' ||
SignUp.clerk.client?.signIn.firstFactorVerification.strategy === 'oauth_microsoft' ||
SignUp.clerk.client?.signIn.firstFactorVerification.strategy === 'oauth_apple')
) {
return true;
}

return false;
}
}