Fix: Turnstile token via getResponse(widgetId), debug log
This commit is contained in:
parent
ca30fde467
commit
08efc258a0
1 changed files with 15 additions and 9 deletions
|
|
@ -44,38 +44,44 @@
|
|||
let formDone = $state(false);
|
||||
let formError = $state('');
|
||||
|
||||
let turnstileToken = $state('');
|
||||
let tsWidgetId = $state<string | null>(null);
|
||||
|
||||
function openModal(plan = '') {
|
||||
modalPlan = plan;
|
||||
formDone = false;
|
||||
formError = '';
|
||||
turnstileToken = '';
|
||||
tsWidgetId = null;
|
||||
showModal = true;
|
||||
setTimeout(() => {
|
||||
const ts = (window as any).turnstile;
|
||||
if (!ts) return;
|
||||
const el = document.querySelector('.cf-turnstile');
|
||||
if (el && !el.hasChildNodes()) {
|
||||
ts.render(el, {
|
||||
if (el) {
|
||||
el.innerHTML = '';
|
||||
tsWidgetId = ts.render(el, {
|
||||
sitekey: PUBLIC_TURNSTILE_SITE_KEY,
|
||||
theme: 'light',
|
||||
callback: (t: string) => { turnstileToken = t; }
|
||||
theme: 'light'
|
||||
});
|
||||
}
|
||||
}, 80);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
const ts = (window as any).turnstile;
|
||||
if (ts && tsWidgetId !== null) ts.remove(tsWidgetId);
|
||||
tsWidgetId = null;
|
||||
showModal = false;
|
||||
(window as any).turnstile?.remove('.cf-turnstile');
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (!formName.trim() || !formEmail.trim()) { formError = 'Bitte Name und E-Mail ausfüllen.'; return; }
|
||||
formSending = true; formError = '';
|
||||
try {
|
||||
const token = turnstileToken;
|
||||
const ts = (window as any).turnstile;
|
||||
const token = tsWidgetId !== null
|
||||
? (ts?.getResponse(tsWidgetId) ?? '')
|
||||
: (ts?.getResponse() ?? '');
|
||||
console.log('Turnstile token length:', token?.length);
|
||||
const res = await fetch('/api/contact', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue