error handling in auth

This commit is contained in:
realaravinth
2021-06-28 23:03:15 +05:30
parent d298ef4719
commit c581d8d0a3
12 changed files with 51 additions and 15 deletions

View File

@@ -18,6 +18,7 @@
import ROUTES from '../../../api/v1/routes';
import genJsonPayload from '../../../utils/genJsonPayload';
import createError from '../../../components/error/index';
const userExists = async () => {
const username = <HTMLInputElement>document.getElementById('username');
@@ -31,12 +32,12 @@ const userExists = async () => {
const data = await res.json();
if (data.exists) {
username.className += ' form__in-field--warn';
alert('Username taken');
createError(`Username "${val}" taken`);
}
return data.exists;
} else {
const err = await res.json();
alert(`error: ${err.error}`);
createError(err.error);
}
return false;
};