Skip to content
Snippets Groups Projects
Commit d61d8d9c authored by Erik Borgeteien Hansen's avatar Erik Borgeteien Hansen
Browse files

fix not sending correct info bug

parent 40211e47
No related branches found
No related tags found
1 merge request!10Register view tailwind
Pipeline #175468 passed
...@@ -122,7 +122,6 @@ export default { ...@@ -122,7 +122,6 @@ export default {
setup: () => ({ v$: useVuelidate() }), setup: () => ({ v$: useVuelidate() }),
data() { data() {
return { return {
userCreated: false,
loading: false, loading: false,
email: "", email: "",
pword: "", pword: "",
...@@ -151,34 +150,25 @@ export default { ...@@ -151,34 +150,25 @@ export default {
}, },
methods: { methods: {
async submit() { async submit() {
console.log(this.$data); //Display loading symbol
this.loading = true; this.loading = true;
const result = await this.v$.$validate();
//Validate form
const result = await this.v$.$validate();
if (!result) { if (!result) {
//Invalid form
console.log("Form not submitted");
this.loading = false; this.loading = false;
return; return;
} }
const registerInfo = { //Send a request to create a user and save success as a bool
email: this.email, const userCreated = await this.sendRegisterRequest();
firstName: this.fname,
lastname: this.lname,
password: this.pword,
address: this.address,
};
let response = await registerUser(registerInfo);
if (response.status === 200) this.userCreated = true;
//If a user is created succsessfully, try to login //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 = { const loginRequest = {
email: this.user.email, email: this.email,
password: this.user.password, password: this.pword,
}; };
const loginResponse = await doLogin(loginRequest); const loginResponse = await doLogin(loginRequest);
...@@ -189,12 +179,24 @@ export default { ...@@ -189,12 +179,24 @@ export default {
this.$router.push("/login"); this.$router.push("/login");
return; return;
} }
this.$router.push("/");
this.$store.commit("saveToken", loginResponse); 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;
}, },
}, },
}; };
......
...@@ -14,9 +14,9 @@ export function registerUser(registerInfo) { ...@@ -14,9 +14,9 @@ export function registerUser(registerInfo) {
return axios return axios
.post(API_URL + "register", { .post(API_URL + "register", {
email: registerInfo.email, email: registerInfo.email,
firstName: registerInfo.fname, firstName: registerInfo.firstName,
lastname: registerInfo.lname, lastname: registerInfo.lastname,
password: registerInfo.pword, password: registerInfo.password,
address: registerInfo.address, address: registerInfo.address,
}) })
.then((response) => { .then((response) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment