From d61d8d9c78dc595133a72081cf45ed48e7d40acf Mon Sep 17 00:00:00 2001 From: Erik Borgeteien Hansen <erik@erikbhan.no> Date: Mon, 25 Apr 2022 12:59:10 +0200 Subject: [PATCH] fix not sending correct info bug --- src/components/RegisterFormComponent.vue | 46 ++++++++++++------------ src/utils/apiutil.js | 6 ++-- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/components/RegisterFormComponent.vue b/src/components/RegisterFormComponent.vue index 254e427..94d3e3d 100644 --- a/src/components/RegisterFormComponent.vue +++ b/src/components/RegisterFormComponent.vue @@ -122,7 +122,6 @@ export default { setup: () => ({ v$: useVuelidate() }), data() { return { - userCreated: false, loading: false, email: "", pword: "", @@ -151,34 +150,25 @@ export default { }, methods: { async submit() { - console.log(this.$data); - + //Display loading symbol this.loading = true; - const result = await this.v$.$validate(); + //Validate form + const result = await this.v$.$validate(); if (!result) { - //Invalid form - console.log("Form not submitted"); this.loading = false; return; } - const registerInfo = { - email: this.email, - firstName: this.fname, - lastname: this.lname, - password: this.pword, - address: this.address, - }; - - let response = await registerUser(registerInfo); - if (response.status === 200) this.userCreated = true; + //Send a request to create a user and save success as a bool + const userCreated = await this.sendRegisterRequest(); //If a user is created succsessfully, try to login - if (this.userCreated) { + //If we get this far, we will be pushed anyway so there is no point updating "loading" + if (userCreated) { const loginRequest = { - email: this.user.email, - password: this.user.password, + email: this.email, + password: this.pword, }; const loginResponse = await doLogin(loginRequest); @@ -189,12 +179,24 @@ export default { this.$router.push("/login"); return; } - this.$router.push("/"); this.$store.commit("saveToken", loginResponse); - console.log(loginResponse); + this.$router.push("/"); } - this.loading = false; + }, + async sendRegisterRequest() { + const registerInfo = { + email: this.email, + firstName: this.fname, + lastname: this.lname, + password: this.pword, + address: this.address, + }; + + const response = await registerUser(registerInfo); + + if (response.status === 200) return true; + return false; }, }, }; diff --git a/src/utils/apiutil.js b/src/utils/apiutil.js index e0f6efc..ab12c9e 100644 --- a/src/utils/apiutil.js +++ b/src/utils/apiutil.js @@ -14,9 +14,9 @@ export function registerUser(registerInfo) { return axios .post(API_URL + "register", { email: registerInfo.email, - firstName: registerInfo.fname, - lastname: registerInfo.lname, - password: registerInfo.pword, + firstName: registerInfo.firstName, + lastname: registerInfo.lastname, + password: registerInfo.password, address: registerInfo.address, }) .then((response) => { -- GitLab