basaran / svelte-recaptcha-v2

Google reCAPTCHA v2 implementation for Svelte SPA, SSR and sveltekit static sites.
https://basaran.github.io/svelte-recaptcha-v2/demo
MIT License
42 stars 14 forks source link

fix for sveltekit #3

Open rallisf1 opened 2 years ago

rallisf1 commented 2 years ago

I am kinda new to this but this should do it.

I replaced "debug" with "@milahu/debug-esm" which is an esm fork of debug. Keep in mind debug v5 will support esm and you should switch back.

I also fixed the lib exports as vite would nag about default exporting.

P.S. You should include the src of the demo so we can test it faster. Remember to load the recaptcha key from env and exclude that in .gitignore

CNeenan commented 2 years ago

This fixed my issue for the debug package but I am getting error:

Uncaught Error: reCAPTCHA placeholder element must be an element or id

Do you have an example of how you included the <Recaptcha> in the html section of the Svelte app?

rallisf1 commented 2 years ago

Tbh this patch only worked for a couple of days for me and another vite update broke it as well. I am now using a version completely stripped out of debug.

Anyways, the html portion looks like:

<form name={name} on:submit|preventDefault={submitHandler}>
...
    <div class="form-control mb-3">
        <Recaptcha
        sitekey={variables.recaptchaKey}
        badge={"inline"}
        size={"invisible"}
        on:error={onCaptchaError}
        on:ready={onCaptchaReady} />
    </div>
...
</form>

apparently I'm using tailwind and have a few functions in my <script> tag to handle the form, enable the submit button onCaptchaReady and handle errors.

CNeenan commented 2 years ago

Thank you will take a look at the other branch, have you seen this error at all?

Uncaught Error: No reCAPTCHA clients exist.
rallisf1 commented 2 years ago

Thank you will take a look at the other branch, have you seen this error at all?

Uncaught Error: No reCAPTCHA clients exist.

no sorry