Google reCAPTCHA v2 implementation for Svelte SPA, SSR and sveltekit static sites.
The svelte-recaptcha-v2 is a Google reCAPTCHA v2 implementation specifically designed for Svelte SPA, SSR, and SvelteKit static sites. It offers various features such as compatibility with Svelte’s server-side rendering, easy integration with third-party form validation libraries, support for both invisible and checkbox reCAPTCHA, event model for intercepting different reCAPTCHA states, and more. The library provides proper DOM cleanup and includes TypeScript definitions for LSP.
To get started with svelte-recaptcha-v2, follow these steps:
import { RecaptchaProvider } from 'svelte-recaptcha-v2';
<RecaptchaProvider sitekey="YOUR_SITE_KEY"></RecaptchaProvider>
import { recaptchaInstance } from 'svelte-recaptcha-v2';
// Example event handler
recaptchaInstance.on('challenge', () => {
// Handle challenge event
});
// More event handlers can be added as needed
import { recaptchaInstance } from 'svelte-recaptcha-v2';
// Example form handler
const handleSubmit = async () => {
const token = await recaptchaInstance.execute();
// Use the token for form submission
};
The svelte-recaptcha-v2 library provides a convenient way to implement Google reCAPTCHA v2 in Svelte applications. It offers compatibility with server-side rendering, SvelteKit, and static site adapters. The library has features like easy integration with third-party form validation libraries, support for invisible or checkbox reCAPTCHA, event model for intercepting reCAPTCHA states, and proper DOM cleanup. Additionally, it includes TypeScript definitions for better development experience.