[Glitch] Fix username availability check being wrongly applied on race conditions

Port ea34d35b32c41cedbddef7f57737da61d984a861 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Claire 2026-02-25 15:30:01 +01:00
parent ae6dbbcc53
commit f6d6dc2605

View File

@ -182,15 +182,25 @@ function loaded() {
({ target }) => { ({ target }) => {
if (!(target instanceof HTMLInputElement)) return; if (!(target instanceof HTMLInputElement)) return;
if (target.value && target.value.length > 0) { const checkedUsername = target.value;
if (checkedUsername && checkedUsername.length > 0) {
axios axios
.get('/api/v1/accounts/lookup', { params: { acct: target.value } }) .get('/api/v1/accounts/lookup', {
params: { acct: checkedUsername },
})
.then(() => { .then(() => {
target.setCustomValidity(formatMessage(messages.usernameTaken)); // Only update the validity if the result is for the currently-typed username
if (checkedUsername === target.value) {
target.setCustomValidity(formatMessage(messages.usernameTaken));
}
return true; return true;
}) })
.catch(() => { .catch(() => {
target.setCustomValidity(''); // Only update the validity if the result is for the currently-typed username
if (checkedUsername === target.value) {
target.setCustomValidity('');
}
}); });
} else { } else {
target.setCustomValidity(''); target.setCustomValidity('');