From 015d67cf738e4ad6d397824dc09a44d85d643b75 Mon Sep 17 00:00:00 2001
From: Mateja <mail@matejamaric.com>
Date: Thu, 29 Jul 2021 02:46:33 +0200
Subject: Fully implement client-side login system...

---
 client/src/App.vue | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

(limited to 'client/src/App.vue')

diff --git a/client/src/App.vue b/client/src/App.vue
index f2bef74..f61f236 100644
--- a/client/src/App.vue
+++ b/client/src/App.vue
@@ -17,7 +17,7 @@
             </router-link>
           </li>
         </ul>
-        <ul class="navbar-nav mb-2 mb-lg-0">
+        <ul class="navbar-nav mb-2 mb-lg-0" v-if="!isLoggedIn">
           <li class="nav-item">
             <router-link class="nav-link" active-class="active" to="/register">Register</router-link>
           </li>
@@ -25,6 +25,11 @@
             <router-link class="nav-link" active-class="active" to="/login">Login</router-link>
           </li>
         </ul>
+        <ul class="navbar-nav mb-2 mb-lg-0" v-else>
+          <li class="nav-item">
+            <span class="nav-link" @click="logout">Logout</span>
+          </li>
+        </ul>
       </div>
     </div>
   </nav>
@@ -34,11 +39,29 @@
 </template>
 
 <script>
+import axios from 'axios';
+
 export default {
-  name: 'Checkout',
+  name: 'App',
+  created() {
+    axios.interceptors.response.use(undefined, error => {
+      if (error.status === 401) {
+        this.$store.commit('auth_clean');
+      }
+      return Promise.reject(error);
+    });
+  },
   computed: {
     cartSize() {
       return this.$store.getters.getCartSize;
+    },
+    isLoggedIn() {
+      return this.$store.getters.isLoggedIn;
+    }
+  },
+  methods: {
+    logout() {
+      this.$store.commit('auth_clean');
     }
   }
 }
-- 
cgit v1.2.3

