(function() { const ViewAuth = () => { const { setUser, showToast, fetchAPI, navigateTo } = window.useApp(); const [loading, setLoading] = React.useState(false); const [formData, setFormData] = React.useState({ username: '', password: '' }); const handleLogin = async (e) => { e.preventDefault(); setLoading(true); try { // Panggil Endpoint API Custom yang kita buat di class-api.php const result = await fetchAPI('/login', { method: 'POST', body: JSON.stringify(formData) }); if (result.success) { showToast("Login Berhasil! Mengalihkan...", "success"); // HARD RELOAD: Kunci arsitektur ini. // Agar cookie WP tersetting dan PHP mengenali user di reload berikutnya. setTimeout(() => { window.location.href = '/console'; }, 1000); } } catch (err) { // Error sudah dihandle oleh fetchAPI (muncul toast) console.error(err); } finally { setLoading(false); } }; return (
Masuk untuk akses Creator Console