Anna Hrechko
Anna Hrechko

Reputation: 11

add google recaptcha to svelte

I am trying to add google recaptcha to svelte app but nothing happens

index.hml

<script src="https://www.google.com/recaptcha/api.js" async defer></script> 

myComponent.svelte

<div class="g-recaptcha" data-sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"></div>

Any thoughts?

Upvotes: 1

Views: 1235

Answers (2)

anakha
anakha

Reputation: 1280

Having a stable recaptcha working with any framework is no straight forward task. You can try the svelte-recaptcha-v2.

Repository

https://github.com/basaran/svelte-recaptcha-v2

Demo Site

https://basaran.github.io/svelte-recaptcha-v2/demo/

P.S I'm the author.

Upvotes: 0

digby280
digby280

Reputation: 899

Using Google APIs like this with Javascript frameworks can be a bit fiddly. I haven't use reCAPTCHA but I've worked with the adsense API. The issue almost always boils down to the appropriate element not being in the DOM when the Google script runs.

With the reCAPTCHA API you can explicitly render the widget. That appears to be what the react and vue components are doing:

Upvotes: 1

Related Questions