From 6d216cf1c0260083a8d9f68e1b7594143f57a7fb Mon Sep 17 00:00:00 2001
From: Titus Kristiansen <titusk@stud.ntnu.no>
Date: Mon, 25 Apr 2022 15:50:23 +0200
Subject: [PATCH] Upgraded the authentication mechanism is apiutil and login

---
 src/components/LoginForm.vue | 12 +++++++++---
 src/utils/apiutil.js         |  7 +++++--
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/components/LoginForm.vue b/src/components/LoginForm.vue
index 82ba58c..835d99b 100644
--- a/src/components/LoginForm.vue
+++ b/src/components/LoginForm.vue
@@ -90,7 +90,7 @@
           >
         </div>
       </div>
-      <div class="flex flex-row min-h-screen justify-center items-center">
+      <div class="flex justify-center">
         <label>{{ message }}</label>
       </div>
     </div>
@@ -153,11 +153,17 @@ export default {
 
       const loginResponse = await doLogin(loginRequest);
 
-      if (loginResponse.data === "Login failed") {
+      if (loginResponse.isLoggedIn === false) {
         this.message = "Feil e-post/passord";
         this.$store.commit("logout");
-      } else {
+      }
+      else if(loginResponse.isLoggedIn === true){
         this.$store.commit("saveToken", loginResponse);
+        this.message = loginResponse.token;
+        console.log("Logged in")
+      }
+      else {
+        console.log("Something went wrong")
       }
     },
 
diff --git a/src/utils/apiutil.js b/src/utils/apiutil.js
index 8812b42..f371b81 100644
--- a/src/utils/apiutil.js
+++ b/src/utils/apiutil.js
@@ -1,13 +1,16 @@
 import axios from "axios";
 
 export function doLogin(loginRequest) {
+  const auth = {isLoggedIn: false, token: ""};
   return axios
     .post(process.env.VUE_APP_BASEURL + "login/authentication", loginRequest)
     .then((response) => {
-      return response.data;
+      auth.isLoggedIn = true;
+      auth.token = response.data;
+      return auth;
     })
     .catch((error) => {
       console.log(error.response);
-      return error.response;
+      return auth;
     });
 }
-- 
GitLab