create login and register functionable

This commit is contained in:
NekoVari 2023-09-27 00:47:59 +07:00
parent eb55b258d9
commit 004c9a697c
2 changed files with 32 additions and 3 deletions

View file

@ -47,6 +47,32 @@ export default {
login() {
if (this.input.username !== '' && this.input.password !== '') {
console.log('Authenticated: Checking with Backend');
fetch(`http://localhost:5000/api/users/login`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username: this.input.username,
password: this.input.password,
}),
})
.then((res) => {
if (res.ok) {
return res.json();
} else {
throw Error(`Login failed (${res.status})`);
}
})
.then((data) => {
console.log(data.loginStatus);
sessionStorage.setItem('current_user', data.userName);
this.$router.push({ name: 'home' });
})
.catch((err) => {
console.log(err);
// Handle the error, e.g., display an error message to the user
});
} else {
console.log('Username and Password cannot be empty');
}

View file

@ -52,10 +52,13 @@
console.log('Authenticated: Checking with Backend');
fetch("http://localhost:5000/api/users/create", {
method: "POST",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: username,
password: password,
email: "",
username: this.input.username,
password: this.input.password,
email: "asdf",
isGoogleAccount: false
})
})