feat: validation for login and register

This commit is contained in:
Damillora 2021-05-21 18:51:44 +07:00
parent 4cac39e83f
commit e79b033c59
2 changed files with 22 additions and 5 deletions

View File

@ -4,10 +4,17 @@
let username = ""; let username = "";
let password = ""; let password = "";
let error = "";
const doLogin = async () => { const doLogin = async () => {
error = "";
try {
const tokenData = await login({ username, password }); const tokenData = await login({ username, password });
navigate("/"); navigate("/");
} catch (e) {
error = "We had trouble logging you in";
return;
}
}; };
</script> </script>
@ -45,6 +52,11 @@
/> />
</div> </div>
</div> </div>
{#if error}
<div class="field">
<p class="has-text-danger">{error}</p>
</div>
{/if}
<div class="field"> <div class="field">
<div class="control"> <div class="control">
<button class="button is-link">Login</button> <button class="button is-link">Login</button>

View File

@ -5,10 +5,15 @@
let username = ""; let username = "";
let password = ""; let password = "";
let email = ""; let email = "";
let error = "";
const doRegister = async () => { const doRegister = async () => {
try {
const tokenData = await register({ email, username, password }); const tokenData = await register({ email, username, password });
navigate("/"); navigate("/");
} catch (error) {
error = "We had trouble registering you";
}
}; };
</script> </script>