Created
April 25, 2024 16:01
-
-
Save andreasnuesslein/c3eb4b162561686ad739837e1495be84 to your computer and use it in GitHub Desktop.
a svelte component for Friendly Captcha (https://friendlycaptcha.com/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script lang="ts"> | |
import { WidgetInstance } from "friendly-challenge" | |
import { createEventDispatcher, onDestroy, onMount } from "svelte" | |
const dispatch = createEventDispatcher<{ solve: string }>() | |
export let sitekey: string | |
let widgetDiv: HTMLDivElement | |
let widget: WidgetInstance | |
onMount(() => { | |
widget = new WidgetInstance(widgetDiv, { | |
doneCallback: (solution: string) => dispatch("solve", solution), | |
sitekey: sitekey, | |
}) | |
widget.start() | |
}) | |
onDestroy(() => { | |
if (widget) widget.destroy() | |
}) | |
</script> | |
<!-- According to the docs https://docs.friendlycaptcha.com/#/widget_api: | |
"This element should contain the `frc-captcha` class for correct styling | |
--> | |
<div class="frc-captcha" bind:this={widgetDiv}></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment