Skip to content

Commit 9395c24

Browse files
committed
register route hooked up with backend
1 parent e5e7697 commit 9395c24

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

frontend/src/views/auth/SignUp.vue

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
22
<!-- eslint-disable max-len -->
33
<div class="auth-container">
4+
<div class="auth-sub-container-error mb-4" v-if="error.happened">
5+
<h1 class="auth-sub-container-error-message">{{error.message}}</h1>
6+
</div>
47
<div class="auth-sub-container">
58
<div class="auth-sub-container-content" v-if="!confirmationEmailSent">
69
<div class="flex justify-center items-center">
@@ -13,11 +16,11 @@
1316
<ValidationObserver v-slot="{ handleSubmit, invalid }">
1417
<form @submit.prevent="handleSubmit(onSubmit)" class="mt-4">
1518
<ValidationProvider name="First Name" rules="required|alpha|max:20" v-slot="{errors}">
16-
<input type="text" placeholder="First Name" v-model="formData.firstName" class="matcha-input">
19+
<input type="text" placeholder="First Name" v-model="formData.first_name" class="matcha-input">
1720
<span class="matcha-input-error">{{ errors[0] }}</span>
1821
</ValidationProvider>
1922
<ValidationProvider name="Last Name" rules="required|alpha|max:20" v-slot="{errors}">
20-
<input type="text" placeholder="Last Name" v-model="formData.lastName" class="matcha-input">
23+
<input type="text" placeholder="Last Name" v-model="formData.last_name" class="matcha-input">
2124
<span class="matcha-input-error">{{ errors[0] }}</span>
2225
</ValidationProvider>
2326
<ValidationProvider name="Email" rules="required|email|max:50" v-slot="{errors}">
@@ -55,13 +58,17 @@
5558
export default {
5659
data: () => ({
5760
formData: {
58-
firstName: '',
59-
lastName: '',
61+
first_name: '',
62+
last_name: '',
6063
email: '',
6164
username: '',
6265
password: '',
6366
},
6467
confirmationEmailSent: false,
68+
error: {
69+
happened: false,
70+
message: '',
71+
},
6572
}),
6673
methods: {
6774
passwordErrorHandler(error) {
@@ -70,8 +77,25 @@ export default {
7077
}
7178
return 'This password is too easy to guess';
7279
},
73-
onSubmit() {
74-
this.confirmationEmailSent = true;
80+
async onSubmit() {
81+
try {
82+
this.clearError();
83+
await this.signUpUser(this.formData);
84+
this.confirmationEmailSent = true;
85+
} catch (error) {
86+
this.displayError(this.$errorMessenger(error));
87+
}
88+
},
89+
async signUpUser(user) {
90+
await this.$http.post('/auth/register', user);
91+
},
92+
clearError() {
93+
this.error.message = '';
94+
this.error.happened = false;
95+
},
96+
displayError(message) {
97+
this.error.message = message;
98+
this.error.happened = true;
7599
},
76100
},
77101
};

0 commit comments

Comments
 (0)