recaptcha-2.tsx 924 B

123456789101112131415161718192021222324252627282930313233343536
  1. import ReCAPTCHA from 'react-google-recaptcha'
  2. import getMeta from '@/utils/meta'
  3. import { ExposedSettings } from '../../../../types/exposed-settings'
  4. interface ReCaptcha2Props
  5. extends Pick<React.ComponentProps<typeof ReCAPTCHA>, 'onChange'> {
  6. page: keyof ExposedSettings['recaptchaDisabled']
  7. recaptchaRef: React.LegacyRef<ReCAPTCHA>
  8. }
  9. export function ReCaptcha2({
  10. page: site,
  11. onChange,
  12. recaptchaRef,
  13. }: ReCaptcha2Props) {
  14. const { recaptchaSiteKey, recaptchaDisabled } = getMeta('ol-ExposedSettings')
  15. if (!recaptchaSiteKey) {
  16. return null
  17. }
  18. if (site && recaptchaDisabled[site]) {
  19. return null
  20. }
  21. if (process.env.NODE_ENV === 'development' && window.Cypress) {
  22. return null // Disable captcha for E2E tests in dev-env.
  23. }
  24. return (
  25. <ReCAPTCHA
  26. ref={recaptchaRef}
  27. size="invisible"
  28. sitekey={recaptchaSiteKey}
  29. onChange={onChange}
  30. badge="inline"
  31. />
  32. )
  33. }