| | |
| | | ob_start(); |
| | | ?> |
| | | |
| | | document.addEventListener('DOMContentLoaded', () => { |
| | | document.addEventListener('DOMContentLoaded', async function () { |
| | | window.auth.subscribe(event => { |
| | | if (event === 'auth-loaded') { |
| | | const form = document.querySelector('.login form'); |
| | | if (!form) return; |
| | | |
| | |
| | | try { |
| | | submit.disabled = true; |
| | | submit.textContent = 'Loading...'; |
| | | const response = await fetch(`${jvbSettings.api}<?=($action === 'magic') ? $action : 'auth/'.$action?>`, { |
| | | const response = await window.auth.fetch(`${jvbSettings.api}auth/<?php echo $action; ?>`, { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | 'X-WP-Nonce': window.auth.getNonce() |
| | | }, |
| | | body: JSON.stringify(realFormData) |
| | | }); |
| | | |
| | |
| | | if (result.redirect) { |
| | | setTimeout(() => { |
| | | window.location.href = result.redirect; |
| | | }, 200); // Brief delay to show success message |
| | | }, 100); // Brief delay to show success message |
| | | } |
| | | |
| | | } catch (error) { |
| | |
| | | submit.disabled = false; |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | }); |
| | | |