BUG register API

This commit is contained in:
NekoVari 2023-09-24 18:35:25 +07:00
parent 54caf6d3ef
commit eb55b258d9
2 changed files with 29 additions and 5 deletions

View file

@ -45,7 +45,7 @@ export default {
}, },
methods: { methods: {
login() { login() {
if (this.input.username !== '' || this.input.password !== '') { if (this.input.username !== '' && this.input.password !== '') {
console.log('Authenticated: Checking with Backend'); console.log('Authenticated: Checking with Backend');
} else { } else {
console.log('Username and Password cannot be empty'); console.log('Username and Password cannot be empty');

View file

@ -21,7 +21,7 @@
</v-form> </v-form>
</v-container> </v-container>
<v-btn @click.prevent="login">สมครสมาช</v-btn> <v-btn @click.prevent="register">สมครสมาช</v-btn>
</v-main> </v-main>
</v-app> </v-app>
@ -47,15 +47,39 @@
}; };
}, },
methods: { methods: {
login() { register() {
if (this.input.username !== '' || this.input.password !== '') { if (this.input.username !== '' && ((this.input.password !='') && (this.input.password == this.input.passwordConfirm))) {
console.log('Authenticated: Checking with Backend'); console.log('Authenticated: Checking with Backend');
fetch("http://localhost:5000/api/users/create", {
method: "POST",
body: JSON.stringify({
username: username,
password: password,
email: "",
isGoogleAccount: false
})
})
.then((res) => {
if(res.ok){
return res.json()
}
else{
return res.json().then(data => {throw Error(`${data.registerStatus}`) });
}
})
.then((data) => {
console.log(data.registerStatus)
this.$router.push({name : 'login'})
})
.catch((err) =>{
console.log(err)
})
console.log("fisnished fetch");
} else { } else {
console.log('Username and Password cannot be empty'); console.log('Username and Password cannot be empty');
} }
} }
} }
}; };
</script> </script>