@graphcommerce/googlerecaptcha 2.0.5 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1378](https://github.com/graphcommerce-org/graphcommerce/pull/1378) [`b610a6e40`](https://github.com/graphcommerce-org/graphcommerce/commit/b610a6e4049e8c9e8b5d2aeff31b8e1bfc24abe5) Thanks [@paales](https://github.com/paales)! - Pin all versions internally so we can’t end up in an unfixable state for the user
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`b610a6e40`](https://github.com/graphcommerce-org/graphcommerce/commit/b610a6e4049e8c9e8b5d2aeff31b8e1bfc24abe5)]:
|
|
10
|
+
- @graphcommerce/graphql@3.0.7
|
|
11
|
+
|
|
12
|
+
## 2.1.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#1369](https://github.com/graphcommerce-org/graphcommerce/pull/1369) [`ae6449502`](https://github.com/graphcommerce-org/graphcommerce/commit/ae64495024a455bbe5188588604368c1542840c9) Thanks [@paales](https://github.com/paales)! - Upgraded dependencies
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a), [`ae6449502`](https://github.com/graphcommerce-org/graphcommerce/commit/ae64495024a455bbe5188588604368c1542840c9), [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a)]:
|
|
19
|
+
- @graphcommerce/graphql@3.0.6
|
|
20
|
+
|
|
21
|
+
## 2.1.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- [#1344](https://github.com/graphcommerce-org/graphcommerce/pull/1344) [`5ab19683c`](https://github.com/graphcommerce-org/graphcommerce/commit/5ab19683ca4e1ff78c21dbe09b73aeea43ef3b64) Thanks [@paales](https://github.com/paales)! - Added Google reCAPTCHA conditional loading to make it fully compatible, but load the reCAPTCHA only on pages with forms.
|
|
26
|
+
|
|
3
27
|
## 2.0.5
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
# @graphcommerce/googlerecaptcha
|
|
2
2
|
|
|
3
|
-
This package makes it easy to add Google Recaptcha v3 to GraphCommerce
|
|
3
|
+
This package makes it easy to add Google Recaptcha v3 to GraphCommerce. It
|
|
4
|
+
allows you to load the Recatcha script conditionally on the page so it isn't
|
|
5
|
+
initialized on all pages.
|
|
4
6
|
|
|
5
|
-
###
|
|
7
|
+
### Installation
|
|
6
8
|
|
|
7
9
|
1. Add `NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY` to your .env file.
|
|
8
10
|
[example](../../examples/magento-graphcms/.env.example)
|
|
9
|
-
2. Add `<
|
|
11
|
+
2. Add `<GoogleRecaptchaProvider/>` to your `pages/_app.tsx` file
|
|
10
12
|
[example](../../examples/magento-graphcms/pages/_app.tsx)
|
|
11
13
|
3. Add `recaptchaLink` to your Apollo Client.
|
|
12
|
-
[example](../../examples/magento-graphcms/lib/
|
|
14
|
+
[example](../../examples/magento-graphcms/lib/graphql/GraphQLProvider.tsx)
|
|
13
15
|
4. Add `X-Recaptcha` header to your `.meshrc.yml`.
|
|
14
16
|
[example](../../examples/magento-graphcms/.meshrc.yml)
|
|
17
|
+
|
|
18
|
+
### Usage
|
|
19
|
+
|
|
20
|
+
If you have a form that uses GoogleRecaptcha add `useGoogleRecaptcha()` in the
|
|
21
|
+
root of your component.
|
|
22
|
+
|
|
23
|
+
### Troubleshooting
|
|
24
|
+
|
|
25
|
+
`ReCaptcha validation failed, please try again`
|
|
26
|
+
: Magento is configured correctly and this is an error coming from Google
|
|
27
|
+
directly. You have misconfigured something on the Google side. Make sure the
|
|
28
|
+
domains are set up correctly, etc.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react'
|
|
2
|
+
import { RecaptchaContext, recaptchaContext } from '../context/recaptchaContext'
|
|
3
|
+
import { GoogleRecaptchaV3Script } from './GoogleRecaptchaV3Script'
|
|
4
|
+
|
|
5
|
+
export function GoogleRecaptchaProvider(props: { children: React.ReactNode; siteKey?: string }) {
|
|
6
|
+
const { children, siteKey = process.env.NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY } = props
|
|
7
|
+
const [enabled, setEnabled] = useState(false)
|
|
8
|
+
|
|
9
|
+
const context: RecaptchaContext = useMemo(
|
|
10
|
+
() => ({ enabled, siteKey, enable: () => setEnabled(true) }),
|
|
11
|
+
[enabled, siteKey],
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<recaptchaContext.Provider value={context}>
|
|
16
|
+
<GoogleRecaptchaV3Script />
|
|
17
|
+
{children}
|
|
18
|
+
</recaptchaContext.Provider>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
+
import { GlobalStyles } from '@mui/material'
|
|
1
2
|
import Script from 'next/script'
|
|
2
|
-
import
|
|
3
|
+
import { useContext } from 'react'
|
|
4
|
+
import { recaptchaContext } from '../context/recaptchaContext'
|
|
3
5
|
|
|
4
6
|
export function GoogleRecaptchaV3Script() {
|
|
5
|
-
const siteKey =
|
|
7
|
+
const { siteKey, enabled } = useContext(recaptchaContext)
|
|
6
8
|
|
|
7
|
-
if (process.env.NODE_ENV !== 'production' && !siteKey)
|
|
9
|
+
if (process.env.NODE_ENV !== 'production' && !siteKey && enabled)
|
|
8
10
|
console.warn(
|
|
9
11
|
'[@graphcommerce/googletagmanager]: NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY not found',
|
|
10
12
|
)
|
|
11
13
|
|
|
12
|
-
if (!siteKey) return null
|
|
14
|
+
if (!siteKey || !enabled) return null
|
|
13
15
|
|
|
14
16
|
return (
|
|
15
17
|
<>
|
|
16
18
|
<Script
|
|
19
|
+
key='google-recaptcha-v3'
|
|
17
20
|
strategy='lazyOnload'
|
|
18
21
|
src={`https://www.google.com/recaptcha/api.js?render=${siteKey}`}
|
|
19
22
|
/>
|
|
20
|
-
<
|
|
23
|
+
<GlobalStyles styles={{ '.grecaptcha-badge': { visibility: 'hidden' } }} />
|
|
21
24
|
</>
|
|
22
25
|
)
|
|
23
26
|
}
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/googlerecaptcha",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.1.2",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,19 +12,19 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@graphcommerce/eslint-config-pwa": "^4.1.
|
|
16
|
-
"@graphcommerce/prettier-config-pwa": "^4.0.
|
|
15
|
+
"@graphcommerce/eslint-config-pwa": "^4.1.4",
|
|
16
|
+
"@graphcommerce/prettier-config-pwa": "^4.0.5",
|
|
17
17
|
"@graphcommerce/typescript-config-pwa": "^4.0.2",
|
|
18
|
-
"@playwright/test": "^1.
|
|
18
|
+
"@playwright/test": "^1.20.1",
|
|
19
19
|
"@types/grecaptcha": "^3.0.4"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@graphcommerce/graphql": "
|
|
22
|
+
"@graphcommerce/graphql": "3.0.7"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"next": "
|
|
25
|
+
"next": "12.1.2",
|
|
26
26
|
"react": "^17.0.2",
|
|
27
27
|
"react-dom": "^17.0.2",
|
|
28
|
-
"@mui/material": "
|
|
28
|
+
"@mui/material": "5.5.3"
|
|
29
29
|
}
|
|
30
30
|
}
|