recaptcha-2.tsx 665 B

123456789101112131415161718192021222324252627
  1. import { forwardRef } from 'react'
  2. import ReCAPTCHA from 'react-google-recaptcha'
  3. const siteKey = window.ExposedSettings.recaptchaSiteKey
  4. const recaptchaDisabled = window.ExposedSettings.recaptchaDisabled
  5. type Page = keyof typeof recaptchaDisabled
  6. export const ReCaptcha2 = forwardRef<
  7. ReCAPTCHA,
  8. { page: Page; onChange?: (token: string | null) => void }
  9. >(function ReCaptcha2({ page: site, onChange }, ref) {
  10. if (!siteKey) {
  11. return null
  12. }
  13. if (site && recaptchaDisabled[site]) {
  14. return null
  15. }
  16. return (
  17. <ReCAPTCHA
  18. ref={ref}
  19. size="invisible"
  20. sitekey={siteKey}
  21. onChange={onChange}
  22. badge="inline"
  23. />
  24. )
  25. })