Fix username availability check being wrongly applied on race conditions (#37975)
This commit is contained in:
@@ -183,15 +183,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('');
|
||||||
|
|||||||
Reference in New Issue
Block a user