@gahojin-inc/react-google-recaptcha 2025.8.1 → 2025.9.1

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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { createContext, useCallback, useContext, useEffect, useId, useMemo, useState } from "react";
1
+ import { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
 
4
4
  //#region src/utils.ts
@@ -15,9 +15,10 @@ const injectScriptTag = (scriptId, language, useRecaptchaNet, useEnterprise, onL
15
15
  script.async = true;
16
16
  script.defer = true;
17
17
  script.onload = onLoad;
18
- const head = document.getElementsByTagName("head")[0];
19
- head.appendChild(script);
20
- return script;
18
+ document.head.appendChild(script);
19
+ return () => {
20
+ document.head.removeChild(script);
21
+ };
21
22
  };
22
23
  const removeScriptTag = () => {
23
24
  removeRecaptchBadge();
@@ -40,30 +41,49 @@ const GoogleReCaptchaContext = createContext({
40
41
  const GoogleReCaptchaProvider = ({ siteKey, language, useRecaptchaNet, useEnterprise, container, badge, theme, children }) => {
41
42
  const id = useId();
42
43
  const containerId = useMemo(() => container ? container : `${id}-container`, [id, container]);
43
- const [state, setState] = useState({
44
- isLoading: true,
45
- widgetId: siteKey
46
- });
44
+ const [state, setState] = useState({ isLoading: true });
45
+ const widgetId = useRef(siteKey);
46
+ const grecaptcha = useRef(null);
47
+ const scriptLoaded = useRef(false);
48
+ const successHandler = useRef(null);
49
+ const errorHandler = useRef(null);
50
+ const handleSuccess = useCallback((token) => {
51
+ if (successHandler.current) {
52
+ successHandler.current?.(token);
53
+ grecaptcha.current?.reset(widgetId.current);
54
+ successHandler.current = null;
55
+ errorHandler.current = null;
56
+ }
57
+ }, []);
58
+ const handleError = useCallback((error) => {
59
+ if (errorHandler.current) {
60
+ errorHandler.current?.(error);
61
+ successHandler.current = null;
62
+ errorHandler.current = null;
63
+ }
64
+ }, []);
47
65
  const onLoad = useCallback(() => {
48
- const grecaptcha = window.grecaptcha?.enterprise ?? window.grecaptcha;
49
- if (!grecaptcha) {
66
+ const instance = window.grecaptcha?.enterprise ?? window.grecaptcha;
67
+ if (!instance) {
50
68
  setState({
51
69
  isLoading: false,
52
- widgetId: siteKey,
53
- error: /* @__PURE__ */ new Error("ReCaptcha is not available")
70
+ error: /* @__PURE__ */ new Error("reCaptcha is not available")
54
71
  });
55
72
  return;
56
73
  }
57
- grecaptcha.ready(() => {
58
- const widgetId = grecaptcha.render(containerId, {
74
+ if (scriptLoaded.current) return;
75
+ scriptLoaded.current = true;
76
+ instance.ready(() => {
77
+ widgetId.current = instance.render(containerId, {
59
78
  sitekey: siteKey,
60
79
  badge,
61
80
  theme,
62
- size: "invisible"
81
+ size: "invisible",
82
+ callback: handleSuccess,
83
+ "error-callback": handleError
63
84
  });
85
+ grecaptcha.current = instance;
64
86
  setState({
65
- widgetId,
66
- grecaptcha,
67
87
  error: null,
68
88
  isLoading: false
69
89
  });
@@ -72,21 +92,33 @@ const GoogleReCaptchaProvider = ({ siteKey, language, useRecaptchaNet, useEnterp
72
92
  siteKey,
73
93
  containerId,
74
94
  badge,
75
- theme
95
+ theme,
96
+ handleSuccess,
97
+ handleError
76
98
  ]);
77
- const execute = useCallback(async (action) => {
78
- const grecaptcha = state?.grecaptcha;
79
- if (grecaptcha?.execute) return await grecaptcha.execute(state.widgetId, action ? { action } : void 0);
80
- throw new Error("ReCaptcha is not available");
81
- }, [state]);
82
99
  const reset = useCallback(() => {
83
- state?.grecaptcha?.reset(state.widgetId);
84
- }, [state]);
100
+ grecaptcha.current?.reset(widgetId.current);
101
+ }, []);
102
+ const execute = useCallback((action) => {
103
+ const instance = grecaptcha.current;
104
+ if (instance?.execute) {
105
+ const promise = new Promise((resolve, reject) => {
106
+ successHandler.current = resolve;
107
+ errorHandler.current = reject;
108
+ });
109
+ return instance.execute(widgetId.current, action ? { action } : void 0).then((token) => {
110
+ if (token) handleSuccess(token);
111
+ return promise;
112
+ });
113
+ }
114
+ return Promise.reject("ReCaptcha is not available");
115
+ }, [handleSuccess]);
85
116
  useEffect(() => {
86
117
  const removeScript = injectScriptTag(id, language, useRecaptchaNet, useEnterprise, onLoad);
87
118
  return () => {
88
- removeScript?.remove();
119
+ removeScript();
89
120
  removeScriptTag();
121
+ scriptLoaded.current = false;
90
122
  };
91
123
  }, [
92
124
  id,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["GoogleReCaptchaContext: Context<GoogleReCaptchaContextType>","value: GoogleReCaptchaContextType"],"sources":["../src/utils.ts","../src/context.tsx","../src/hooks.ts"],"sourcesContent":["export const getRecaptchaScriptSrc = (\n render: string,\n language: string | null | undefined,\n useRecaptchaNet: boolean | undefined,\n useEnterprise: boolean | undefined,\n): string => {\n const hostName = useRecaptchaNet ? 'recaptcha.net' : 'google.com'\n const script = useEnterprise ? 'enterprise.js' : 'api.js'\n\n return `https://${hostName}/recaptcha/${script}?render=${render}${language ? `&hl=${language}` : ''}`\n}\n\nexport const injectScriptTag = (\n scriptId: string,\n language: string | null | undefined,\n useRecaptchaNet: boolean | undefined,\n useEnterprise: boolean | undefined,\n onLoad: () => void,\n): HTMLScriptElement => {\n const script = document.createElement('script')\n script.type = 'text/javascript'\n script.id = scriptId\n script.src = getRecaptchaScriptSrc('explicit', language, useRecaptchaNet, useEnterprise)\n script.async = true\n script.defer = true\n script.onload = onLoad\n\n const head = document.getElementsByTagName('head')[0]\n head.appendChild(script)\n return script\n}\n\nexport const removeScriptTag = (): void => {\n removeRecaptchBadge()\n\n const script = document.querySelector('script[src^=\"https://www.gstatic.com/recaptcha/releases\"]')\n if (script) {\n script.remove()\n }\n}\n\nexport const removeRecaptchBadge = (): void => {\n const nodeBadge = document.querySelector('.grecaptcha-badge')\n if (nodeBadge?.parentNode) {\n document.body.removeChild(nodeBadge.parentNode)\n }\n}\n","import { type Context, createContext, type JSX, useCallback, useEffect, useId, useMemo, useState } from 'react'\nimport type { GoogleReCaptchaContextType, GoogleReCaptchaProviderProps, Grecaptcha } from './types'\nimport { injectScriptTag, removeScriptTag } from './utils.ts'\n\nconst GoogleReCaptchaContext: Context<GoogleReCaptchaContextType> = createContext<GoogleReCaptchaContextType>({\n isLoading: true,\n error: null,\n execute: () => Promise.reject('useGoogleRecaptcha must be used within an GoogleReCaptchaProvider'),\n reset: () => [],\n})\n\ntype State = {\n isLoading: boolean\n error?: Error | null\n widgetId: string\n grecaptcha?: Grecaptcha | null\n}\n\nconst GoogleReCaptchaProvider = ({\n siteKey,\n language,\n useRecaptchaNet,\n useEnterprise,\n container,\n badge,\n theme,\n children,\n}: GoogleReCaptchaProviderProps): JSX.Element => {\n const id = useId()\n const containerId = useMemo(() => (container ? container : `${id}-container`), [id, container])\n const [state, setState] = useState<State>({ isLoading: true, widgetId: siteKey })\n\n // ReCaptcha初期化\n const onLoad = useCallback(() => {\n const grecaptcha = window.grecaptcha?.enterprise ?? window.grecaptcha\n if (!grecaptcha) {\n setState({\n isLoading: false,\n widgetId: siteKey,\n error: new Error('ReCaptcha is not available'),\n })\n return\n }\n grecaptcha.ready(() => {\n const widgetId = grecaptcha.render(containerId, {\n sitekey: siteKey,\n badge,\n theme,\n size: 'invisible',\n })\n setState({\n widgetId,\n grecaptcha,\n error: null,\n isLoading: false,\n })\n })\n }, [siteKey, containerId, badge, theme])\n\n const execute = useCallback(\n async (action?: string) => {\n const grecaptcha = state?.grecaptcha\n if (grecaptcha?.execute) {\n return await grecaptcha.execute(state.widgetId, action ? { action } : undefined)\n }\n throw new Error('ReCaptcha is not available')\n },\n [state],\n )\n\n const reset = useCallback(() => {\n state?.grecaptcha?.reset(state.widgetId)\n }, [state])\n\n // scriptタグを追加/削除する\n useEffect(() => {\n const removeScript = injectScriptTag(id, language, useRecaptchaNet, useEnterprise, onLoad)\n return () => {\n removeScript?.remove()\n removeScriptTag()\n }\n }, [id, language, useRecaptchaNet, useEnterprise, onLoad])\n\n const value: GoogleReCaptchaContextType = useMemo(\n () => ({\n isLoading: state.isLoading,\n error: state.error ?? null,\n execute,\n reset,\n }),\n [state, execute, reset],\n )\n\n return (\n <GoogleReCaptchaContext.Provider value={value}>\n {children}\n {container ? null : <div id={`${id}-container`} />}\n </GoogleReCaptchaContext.Provider>\n )\n}\n\nexport { GoogleReCaptchaProvider, GoogleReCaptchaContext }\nexport type { GoogleReCaptchaContextType, GoogleReCaptchaProviderProps }\n","import { useContext } from 'react'\nimport { GoogleReCaptchaContext, type GoogleReCaptchaContextType } from './context'\n\nconst useGoogleRecaptcha = (): GoogleReCaptchaContextType => {\n return useContext(GoogleReCaptchaContext)\n}\n\nexport { useGoogleRecaptcha }\n"],"mappings":";;;;AAAA,MAAa,yBACX,QACA,UACA,iBACA,kBACW;CACX,MAAM,WAAW,kBAAkB,kBAAkB;CACrD,MAAM,SAAS,gBAAgB,kBAAkB;AAEjD,QAAO,WAAW,SAAS,aAAa,OAAO,UAAU,SAAS,WAAW,OAAO,aAAa;AAClG;AAED,MAAa,mBACX,UACA,UACA,iBACA,eACA,WACsB;CACtB,MAAM,SAAS,SAAS,cAAc;AACtC,QAAO,OAAO;AACd,QAAO,KAAK;AACZ,QAAO,MAAM,sBAAsB,YAAY,UAAU,iBAAiB;AAC1E,QAAO,QAAQ;AACf,QAAO,QAAQ;AACf,QAAO,SAAS;CAEhB,MAAM,OAAO,SAAS,qBAAqB,QAAQ;AACnD,MAAK,YAAY;AACjB,QAAO;AACR;AAED,MAAa,wBAA8B;AACzC;CAEA,MAAM,SAAS,SAAS,cAAc;AACtC,KAAI,OACF,QAAO;AAEV;AAED,MAAa,4BAAkC;CAC7C,MAAM,YAAY,SAAS,cAAc;AACzC,KAAI,WAAW,WACb,UAAS,KAAK,YAAY,UAAU;AAEvC;;;;AC1CD,MAAMA,yBAA8D,cAA0C;CAC5G,WAAW;CACX,OAAO;CACP,eAAe,QAAQ,OAAO;CAC9B,aAAa,EAAE;CAChB;AASD,MAAM,2BAA2B,EAC/B,SACA,UACA,iBACA,eACA,WACA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1
+ {"version":3,"file":"index.mjs","names":["GoogleReCaptchaContext: Context<GoogleReCaptchaContextType>","value: GoogleReCaptchaContextType"],"sources":["../src/utils.ts","../src/context.tsx","../src/hooks.ts"],"sourcesContent":["export const getRecaptchaScriptSrc = (\n render: string,\n language: string | null | undefined,\n useRecaptchaNet: boolean | undefined,\n useEnterprise: boolean | undefined,\n): string => {\n const hostName = useRecaptchaNet ? 'recaptcha.net' : 'google.com'\n const script = useEnterprise ? 'enterprise.js' : 'api.js'\n\n return `https://${hostName}/recaptcha/${script}?render=${render}${language ? `&hl=${language}` : ''}`\n}\n\nexport const injectScriptTag = (\n scriptId: string,\n language: string | null | undefined,\n useRecaptchaNet: boolean | undefined,\n useEnterprise: boolean | undefined,\n onLoad: () => void,\n): (() => void) => {\n const script = document.createElement('script')\n script.type = 'text/javascript'\n script.id = scriptId\n script.src = getRecaptchaScriptSrc('explicit', language, useRecaptchaNet, useEnterprise)\n script.async = true\n script.defer = true\n script.onload = onLoad\n\n document.head.appendChild(script)\n return () => {\n document.head.removeChild(script)\n }\n}\n\nexport const removeScriptTag = (): void => {\n removeRecaptchBadge()\n\n const script = document.querySelector('script[src^=\"https://www.gstatic.com/recaptcha/releases\"]')\n if (script) {\n script.remove()\n }\n}\n\nexport const removeRecaptchBadge = (): void => {\n const nodeBadge = document.querySelector('.grecaptcha-badge')\n if (nodeBadge?.parentNode) {\n document.body.removeChild(nodeBadge.parentNode)\n }\n}\n","import { type Context, createContext, type JSX, useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport type { GoogleReCaptchaContextType, GoogleReCaptchaProviderProps, Grecaptcha } from './types'\nimport { injectScriptTag, removeScriptTag } from './utils.ts'\n\nconst GoogleReCaptchaContext: Context<GoogleReCaptchaContextType> = createContext<GoogleReCaptchaContextType>({\n isLoading: true,\n error: null,\n execute: () => Promise.reject('useGoogleRecaptcha must be used within an GoogleReCaptchaProvider'),\n reset: () => [],\n})\n\ntype State = {\n isLoading: boolean\n error?: Error | null\n}\n\nconst GoogleReCaptchaProvider = ({\n siteKey,\n language,\n useRecaptchaNet,\n useEnterprise,\n container,\n badge,\n theme,\n children,\n}: GoogleReCaptchaProviderProps): JSX.Element => {\n const id = useId()\n const containerId = useMemo(() => (container ? container : `${id}-container`), [id, container])\n const [state, setState] = useState<State>({ isLoading: true })\n\n const widgetId = useRef<string>(siteKey)\n const grecaptcha = useRef<Grecaptcha>(null)\n const scriptLoaded = useRef(false)\n const successHandler = useRef<(token: string) => void>(null)\n const errorHandler = useRef<(error: Error | undefined) => void>(null)\n\n const handleSuccess = useCallback((token: string) => {\n if (successHandler.current) {\n successHandler.current?.(token)\n // トークンを再度取得できるよう、リセットする\n grecaptcha.current?.reset(widgetId.current)\n successHandler.current = null\n errorHandler.current = null\n }\n }, [])\n\n const handleError = useCallback((error: Error | undefined) => {\n if (errorHandler.current) {\n errorHandler.current?.(error)\n successHandler.current = null\n errorHandler.current = null\n }\n }, [])\n\n // ReCaptcha初期化\n const onLoad = useCallback(() => {\n const instance = window.grecaptcha?.enterprise ?? window.grecaptcha\n if (!instance) {\n setState({\n isLoading: false,\n error: new Error('reCaptcha is not available'),\n })\n return\n }\n\n // 二重にrender実行されることを抑止\n if (scriptLoaded.current) {\n return\n }\n scriptLoaded.current = true\n\n instance.ready(() => {\n widgetId.current = instance.render(containerId, {\n sitekey: siteKey,\n badge,\n theme,\n size: 'invisible',\n callback: handleSuccess,\n 'error-callback': handleError,\n })\n grecaptcha.current = instance\n setState({\n error: null,\n isLoading: false,\n })\n })\n }, [siteKey, containerId, badge, theme, handleSuccess, handleError])\n\n const reset = useCallback(() => {\n grecaptcha.current?.reset(widgetId.current)\n }, [])\n\n const execute = useCallback(\n (action?: string) => {\n const instance = grecaptcha.current\n if (instance?.execute) {\n const promise = new Promise<string>((resolve, reject) => {\n successHandler.current = resolve\n errorHandler.current = reject\n })\n return instance.execute(widgetId.current, action ? { action } : undefined).then((token) => {\n if (token) {\n handleSuccess(token)\n }\n // token = nullの場合、v2動作\n return promise\n })\n }\n return Promise.reject('ReCaptcha is not available')\n },\n [handleSuccess],\n )\n\n // scriptタグを追加/削除する\n useEffect(() => {\n const removeScript = injectScriptTag(id, language, useRecaptchaNet, useEnterprise, onLoad)\n return () => {\n removeScript()\n removeScriptTag()\n scriptLoaded.current = false\n }\n }, [id, language, useRecaptchaNet, useEnterprise, onLoad])\n\n const value: GoogleReCaptchaContextType = useMemo(\n () => ({\n isLoading: state.isLoading,\n error: state.error ?? null,\n execute,\n reset,\n }),\n [state, execute, reset],\n )\n\n return (\n <GoogleReCaptchaContext.Provider value={value}>\n {children}\n {container ? null : <div id={`${id}-container`} />}\n </GoogleReCaptchaContext.Provider>\n )\n}\n\nexport { GoogleReCaptchaProvider, GoogleReCaptchaContext }\nexport type { GoogleReCaptchaContextType, GoogleReCaptchaProviderProps }\n","import { useContext } from 'react'\nimport { GoogleReCaptchaContext, type GoogleReCaptchaContextType } from './context'\n\nconst useGoogleRecaptcha = (): GoogleReCaptchaContextType => {\n return useContext(GoogleReCaptchaContext)\n}\n\nexport { useGoogleRecaptcha }\n"],"mappings":";;;;AAAA,MAAa,yBACX,QACA,UACA,iBACA,kBACW;CACX,MAAM,WAAW,kBAAkB,kBAAkB;CACrD,MAAM,SAAS,gBAAgB,kBAAkB;AAEjD,QAAO,WAAW,SAAS,aAAa,OAAO,UAAU,SAAS,WAAW,OAAO,aAAa;;AAGnG,MAAa,mBACX,UACA,UACA,iBACA,eACA,WACiB;CACjB,MAAM,SAAS,SAAS,cAAc;AACtC,QAAO,OAAO;AACd,QAAO,KAAK;AACZ,QAAO,MAAM,sBAAsB,YAAY,UAAU,iBAAiB;AAC1E,QAAO,QAAQ;AACf,QAAO,QAAQ;AACf,QAAO,SAAS;AAEhB,UAAS,KAAK,YAAY;AAC1B,cAAa;AACX,WAAS,KAAK,YAAY;;;AAI9B,MAAa,wBAA8B;AACzC;CAEA,MAAM,SAAS,SAAS,cAAc;AACtC,KAAI,OACF,QAAO;;AAIX,MAAa,4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,aAAW,SAAS,MAAM,SAAS;IAClC;CAEH,MAAM,UAAU,aACb,WAAoB;EACnB,MAAM,WAAW,WAAW;AAC5B,MAAI,UAAU,SAAS;GACrB,MAAM,UAAU,IAAI,SAAiB,SAAS,WAAW;AACvD,mBAAe,UAAU;AACzB,iBAAa,UAAU;;AAEzB,UAAO,SAAS,QAAQ,SAAS,SAAS,SAAS,EAAE,WAAW,QAAW,MAAM,UAAU;AACzF,QAAI,MACF,eAAc;AAGhB,WAAO;;;AAGX,SAAO,QAAQ,OAAO;IAExB,CAAC;AAIH,iBAAgB;EACd,MAAM,eAAe,gBAAgB,IAAI,UAAU,iBAAiB,eAAe;AACnF,eAAa;AACX;AACA;AACA,gBAAa,UAAU;;IAExB;EAAC;EAAI;EAAU;EAAiB;EAAe;;CAElD,MAAMC,QAAoC,eACjC;EACL,WAAW,MAAM;EACjB,OAAO,MAAM,SAAS;EACtB;EACA;KAEF;EAAC;EAAO;EAAS;;AAGnB,QACE,qBAAC,uBAAuB;EAAgB;aACrC,UACA,YAAY,OAAO,oBAAC,SAAI,IAAI,GAAG,GAAG;;;;;;ACrIzC,MAAM,2BAAuD;AAC3D,QAAO,WAAW"}
package/dist/types.d.mts CHANGED
@@ -8,6 +8,8 @@ export type Parameters = {
8
8
  badge?: Badge;
9
9
  size?: Size;
10
10
  theme?: Theme;
11
+ callback?: (token: string) => void;
12
+ "error-callback"?: (error?: Error) => void;
11
13
  };
12
14
  export type GoogleReCaptchaProviderProps = PropsWithChildren<{
13
15
  readonly siteKey: string;
@@ -24,7 +26,7 @@ export type Action = {
24
26
  export type Grecaptcha = {
25
27
  ready: (onReady: () => void) => void;
26
28
  render: (container: string | HTMLElement, params: Parameters) => string;
27
- execute: (widgetId: string, params?: Action) => Promise<string>;
29
+ execute: (widgetId: string, params?: Action) => Promise<string | null>;
28
30
  reset: (widgetId: string) => void;
29
31
  };
30
32
  export type GoogleReCaptchaContextType = {
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,4 @@
1
1
  export declare const getRecaptchaScriptSrc: (render: string, language: string | null | undefined, useRecaptchaNet: boolean | undefined, useEnterprise: boolean | undefined) => string;
2
- export declare const injectScriptTag: (scriptId: string, language: string | null | undefined, useRecaptchaNet: boolean | undefined, useEnterprise: boolean | undefined, onLoad: () => void) => HTMLScriptElement;
2
+ export declare const injectScriptTag: (scriptId: string, language: string | null | undefined, useRecaptchaNet: boolean | undefined, useEnterprise: boolean | undefined, onLoad: () => void) => (() => void);
3
3
  export declare const removeScriptTag: () => void;
4
4
  export declare const removeRecaptchBadge: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gahojin-inc/react-google-recaptcha",
3
- "version": "2025.8.1",
3
+ "version": "2025.9.1",
4
4
  "description": "Hooks for Google ReCaptcha V3",
5
5
  "author": "GAHOJIN, Inc.",
6
6
  "license": "Apache-2.0",
@@ -17,6 +17,8 @@
17
17
  ],
18
18
  "keywords": [
19
19
  "google-recaptcha",
20
+ "google-recaptcha-v2",
21
+ "google-recaptcha-v3",
20
22
  "react"
21
23
  ],
22
24
  "publishConfig": {