diff --git a/src/views/Login.vue b/src/views/Login.vue index a97e54f..9853b5d 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -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'); } diff --git a/src/views/Register.vue b/src/views/Register.vue index 02c35c2..563711a 100644 --- a/src/views/Register.vue +++ b/src/views/Register.vue @@ -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 }) })