From 01c116045977e1e15748c8adbfd466fd49027996 Mon Sep 17 00:00:00 2001 From: jamesqquick Date: Fri, 20 Feb 2026 09:40:46 -0600 Subject: [PATCH 01/13] added recaptcha v3 --- .../register/_actions/register-customer.ts | 10 +++- .../(default)/(auth)/register/page.tsx | 7 +++ core/app/[locale]/(default)/layout.tsx | 8 ++- .../product/[slug]/_actions/submit-review.ts | 10 +++- .../product/[slug]/_components/reviews.tsx | 7 +++ .../contact/_actions/submit-contact-form.ts | 10 +++- .../(default)/webpages/[id]/contact/page.tsx | 7 +++ core/components/recaptcha-provider/index.tsx | 42 ++++++++++++++++ core/lib/recaptcha.ts | 50 +++++++++++++++++++ core/package.json | 1 + core/vibes/soul/form/dynamic-form/index.tsx | 45 +++++++++++++++-- .../sections/dynamic-form-section/index.tsx | 3 ++ core/vibes/soul/sections/reviews/index.tsx | 7 +++ .../soul/sections/reviews/review-form.tsx | 44 ++++++++++++++-- 14 files changed, 235 insertions(+), 16 deletions(-) create mode 100644 core/components/recaptcha-provider/index.tsx create mode 100644 core/lib/recaptcha.ts diff --git a/core/app/[locale]/(default)/(auth)/register/_actions/register-customer.ts b/core/app/[locale]/(default)/(auth)/register/_actions/register-customer.ts index cd7259ab16..e0df4d6c6e 100644 --- a/core/app/[locale]/(default)/(auth)/register/_actions/register-customer.ts +++ b/core/app/[locale]/(default)/(auth)/register/_actions/register-customer.ts @@ -14,13 +14,14 @@ import { graphql, VariablesOf } from '~/client/graphql'; import { FieldNameToFieldId } from '~/data-transformers/form-field-transformer/utils'; import { redirect } from '~/i18n/routing'; import { getCartId } from '~/lib/cart'; +import { RECAPTCHA_TOKEN_FORM_KEY } from '~/lib/recaptcha'; import { ADDRESS_FIELDS_NAME_PREFIX, CUSTOMER_FIELDS_NAME_PREFIX } from './prefixes'; const RegisterCustomerMutation = graphql(` - mutation RegisterCustomerMutation($input: RegisterCustomerInput!) { + mutation RegisterCustomerMutation($input: RegisterCustomerInput!, $reCaptchaV2: ReCaptchaV2Input) { customer { - registerCustomer(input: $input) { + registerCustomer(input: $input, reCaptchaV2: $reCaptchaV2) { customer { firstName lastName @@ -358,10 +359,15 @@ export async function registerCustomer( try { const input = parseRegisterCustomerInput(submission.value, fields); + const recaptchaToken = formData.get(RECAPTCHA_TOKEN_FORM_KEY); const response = await client.fetch({ document: RegisterCustomerMutation, variables: { input, + reCaptchaV2: + typeof recaptchaToken === 'string' && recaptchaToken + ? { token: recaptchaToken } + : undefined, }, fetchOptions: { cache: 'no-store' }, }); diff --git a/core/app/[locale]/(default)/(auth)/register/page.tsx b/core/app/[locale]/(default)/(auth)/register/page.tsx index bf8ebf1357..4591c6a851 100644 --- a/core/app/[locale]/(default)/(auth)/register/page.tsx +++ b/core/app/[locale]/(default)/(auth)/register/page.tsx @@ -8,6 +8,7 @@ import { formFieldTransformer, injectCountryCodeOptions, } from '~/data-transformers/form-field-transformer'; +import { getReCaptchaSettings } from '~/lib/recaptcha'; import { CUSTOMER_FIELDS_TO_EXCLUDE, REGISTER_CUSTOMER_FORM_LAYOUT, @@ -63,6 +64,11 @@ export default async function Register({ params }: Props) { const { addressFields, customerFields, countries, passwordComplexitySettings } = registerCustomerData; + const reCaptchaSettings = await getReCaptchaSettings(); + const recaptchaEnabled = + (reCaptchaSettings?.isEnabledOnStorefront === true && Boolean(reCaptchaSettings?.siteKey)) ?? + false; + const fields = transformFieldsToLayout( [ ...addressFields.map((field) => { @@ -109,6 +115,7 @@ export default async function Register({ params }: Props) { return ( ; @@ -13,13 +15,15 @@ export default async function DefaultLayout({ params, children }: Props) { setRequestLocale(locale); + const reCaptchaSettings = await getReCaptchaSettings(); + return ( - <> +
{children}