diff --git a/js/src/components/Account/Login.vue b/js/src/components/Account/Login.vue index 35897bc41..cfc319cf6 100644 --- a/js/src/components/Account/Login.vue +++ b/js/src/components/Account/Login.vue @@ -92,10 +92,7 @@ }; rules = { required: value => !!value || 'Required.', - email: (value) => { - const pattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; - return pattern.test(value) || 'Invalid e-mail.'; - }, + email: (value) => value.includes('@') || 'Invalid e-mail.', }; user: any; @@ -110,24 +107,25 @@ this.credentials.password = this.password; } - loginAction(e: Event) { + async loginAction(e: Event) { e.preventDefault(); - this.$apollo.mutate({ - mutation: LOGIN, - variables: { - email: this.credentials.email, - password: this.credentials.password, - }, - }).then((result) => { - console.log(result) + try { + const result = await this.$apollo.mutate({ + mutation: LOGIN, + variables: { + email: this.credentials.email, + password: this.credentials.password, + }, + }); + this.saveUserData(result.data); this.$router.push({ name: 'Home' }); - }).catch((e) => { - console.log(e); + } catch (err) { + console.error(err); this.error.show = true; - this.error.text = e.message; - }); + this.error.text = err.message; + } } validEmail() { @@ -136,7 +134,6 @@ saveUserData({ login: login }) { localStorage.setItem(AUTH_USER_ID, login.user.id); - localStorage.setItem(AUTH_USER_ACTOR, JSON.stringify(login.actor)); localStorage.setItem(AUTH_TOKEN, login.token); } } diff --git a/js/src/components/Account/Register.vue b/js/src/components/Account/Register.vue index d3010c55c..114521dc7 100644 --- a/js/src/components/Account/Register.vue +++ b/js/src/components/Account/Register.vue @@ -121,12 +121,9 @@ }, }; rules = { - password_length: value => value.length > 6 || 'Password must be at least 6 caracters long', + password_length: value => value.length > 6 || 'Password must be at least 6 characters long', required: value => !!value || 'Required.', - email: (value) => { - const pattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; - return pattern.test(value) || 'Invalid e-mail.'; - }, + email: (value: string) => value.includes('@') || 'Invalid e-mail.', }; resetState() { @@ -154,20 +151,21 @@ return this.rules.email(this.email) === true ? 'v-gravatar' : 'avatar'; } - submit() { - this.$apollo.mutate({ - mutation: CREATE_USER, - variables: { - email: this.email, - password: this.password, - username: this.username, - }, - }).then((data) => { - console.log(data); + async submit() { + try { + await this.$apollo.mutate({ + mutation: CREATE_USER, + variables: { + email: this.email, + password: this.password, + username: this.username, + }, + }); + this.validationSent = true; - }).catch((error) => { + } catch (error) { console.error(error); - }); + } } }; diff --git a/js/src/components/Account/Validate.vue b/js/src/components/Account/Validate.vue index 32815d7f5..a9d2a1f72 100644 --- a/js/src/components/Account/Validate.vue +++ b/js/src/components/Account/Validate.vue @@ -19,7 +19,7 @@