mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix: load turnstile script in layout and explicitly render
chore: npm run format + lint
This commit is contained in:
@@ -5,9 +5,16 @@
|
||||
import Navbar from '$lib/components/Navbar.svelte';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { startTokenRefreshInterval, getToken, refreshTokenIfNeeded } from '$lib/utils/auth';
|
||||
import { page } from '$app/state';
|
||||
import type { LayoutData } from './$types';
|
||||
|
||||
export let data: LayoutData;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
startTokenRefreshInterval();
|
||||
window.turnstileLoaded = () => {
|
||||
window.dispatchEvent(new CustomEvent('turnstile:loaded'));
|
||||
};
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
@@ -29,6 +36,13 @@
|
||||
|
||||
<svelte:head>
|
||||
<link rel="icon" href={favicon} />
|
||||
{#if data.options?.cf_turnstile_site_key && (page.url.pathname === '/login' || page.url.pathname === '/register')}
|
||||
<script
|
||||
src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=turnstileLoaded"
|
||||
async
|
||||
defer
|
||||
></script>
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
<Navbar />
|
||||
|
||||
Reference in New Issue
Block a user