mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-29 11:06:10 +00:00
web/Turnstile: check if already defined before making listener
This commit is contained in:
parent
fc26032048
commit
b5d570c43f
|
@ -1,6 +1,7 @@
|
|||
<script lang="ts">
|
||||
import env from "$lib/env";
|
||||
import { onMount } from "svelte";
|
||||
import { browser } from "$app/environment";
|
||||
|
||||
import { turnstileLoaded } from "$lib/state/turnstile";
|
||||
|
||||
|
@ -10,8 +11,7 @@
|
|||
onMount(() => {
|
||||
const sitekey = env.TURNSTILE_KEY;
|
||||
if (!sitekey) return;
|
||||
|
||||
turnstileScript.addEventListener("load", () => {
|
||||
const setup = () => {
|
||||
window.turnstile?.render(turnstileElement, {
|
||||
sitekey,
|
||||
"error-callback": (error) => {
|
||||
|
@ -22,7 +22,13 @@
|
|||
$turnstileLoaded = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (window.turnstile) {
|
||||
setup();
|
||||
} else {
|
||||
turnstileScript.addEventListener("load", setup);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in a new issue