web/Turnstile: check if already defined before making listener
This commit is contained in:
parent
fc26032048
commit
b5d570c43f
1 changed files with 9 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import env from "$lib/env";
|
import env from "$lib/env";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
import { browser } from "$app/environment";
|
||||||
|
|
||||||
import { turnstileLoaded } from "$lib/state/turnstile";
|
import { turnstileLoaded } from "$lib/state/turnstile";
|
||||||
|
|
||||||
|
@ -10,8 +11,7 @@
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const sitekey = env.TURNSTILE_KEY;
|
const sitekey = env.TURNSTILE_KEY;
|
||||||
if (!sitekey) return;
|
if (!sitekey) return;
|
||||||
|
const setup = () => {
|
||||||
turnstileScript.addEventListener("load", () => {
|
|
||||||
window.turnstile?.render(turnstileElement, {
|
window.turnstile?.render(turnstileElement, {
|
||||||
sitekey,
|
sitekey,
|
||||||
"error-callback": (error) => {
|
"error-callback": (error) => {
|
||||||
|
@ -22,7 +22,13 @@
|
||||||
$turnstileLoaded = true;
|
$turnstileLoaded = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (window.turnstile) {
|
||||||
|
setup();
|
||||||
|
} else {
|
||||||
|
turnstileScript.addEventListener("load", setup);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue