shortcode is in a separate Elementor Shortcode widget, then refresh the page.', true);
return;
}
if (!email || !password || !email.value.trim() || !password.value) {
showMessage('Enter your email address and password.', true);
return;
}
if (submit) {
submit.disabled = true;
submit.textContent = 'Signing In...';
}
try {
var body = new URLSearchParams();
body.append('action', 'brit_custom_login');
body.append('nonce', config.nonce);
body.append('email', email.value.trim());
body.append('password', password.value);
body.append('remember', remember && remember.checked ? '1' : '0');
var response;
try {
response = await fetch(config.ajaxUrl, {
method: 'POST',
credentials: 'same-origin',
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
body: body.toString(),
cache: 'no-store'
});
} catch (networkError) {
showMessage('The browser could not reach the WordPress login address. Check that the website is online and that this page uses HTTPS.', true);
return;
}
var rawResponse = await response.text();
var result;
try {
result = JSON.parse(rawResponse);
} catch (parseError) {
if (rawResponse.trim() === '-1' || response.status === 403) {
showMessage('WordPress rejected the login security token. Refresh the login page. If this continues, exclude the login page from page caching.', true);
} else if (response.status === 404) {
showMessage('WordPress could not find its AJAX login endpoint. Check the WordPress site URL and permalink configuration.', true);
} else if (response.status >= 500) {
showMessage('The website server returned an error while processing login. Check the WordPress/PHP error log or contact your hosting provider.', true);
} else {
showMessage('WordPress returned an unexpected response (HTTP ' + response.status + '). The request reached the website, but its response was not valid JSON.', true);
}
return;
}
if (!response.ok || !result || !result.success) {
var data = result && result.data ? result.data : {};
showMessage(data.message || 'WordPress rejected the login request (HTTP ' + response.status + ').', true);
return;
}
showMessage((result.data && result.data.message) || 'Login successful. Redirecting...', false);
window.location.assign((result.data && result.data.redirect) || '/customer-dashboard/');
} catch (error) {
showMessage('The login request could not be completed in the browser. Refresh the page and try again. If it repeats, check the browser console for the exact error.', true);
} finally {
if (submit) {
submit.disabled = false;
submit.textContent = 'Sign In';
}
}
}, true);
})();