Spaces:
Sleeping
Sleeping
File size: 1,142 Bytes
d70361b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | // Forgot Password page. Reuses ddaApi()/showDdaError()/showDdaSuccess() from shared.js.
(function () {
const form = document.getElementById('forgot-form');
const emailInput = document.getElementById('email');
const submitBtn = document.getElementById('forgot-submit');
form.addEventListener('submit', async (e) => {
e.preventDefault();
hideDdaError();
const email = emailInput.value.trim();
if (!email) {
showDdaError('Enter your email address.');
return;
}
submitBtn.disabled = true;
try {
const data = await ddaApi('POST', '/api/auth/forgot-password', { body: JSON.stringify({ email }) });
showDdaSuccess(data.message || 'If an account exists for that email, a reset link has been sent.');
form.reset();
} catch (err) {
// The endpoint always returns 200 regardless of whether the email
// exists — a caught error here means something actually broke
// (network, server error), not "no such account".
showDdaError(err.message || 'Something went wrong. Please try again.');
} finally {
submitBtn.disabled = false;
}
});
})();
|