瀏覽代碼

Login and logout

master
LeneS 5 年之前
父節點
當前提交
9888d2fa08
共有 3 個檔案被更改,包括 21 行新增13 行删除
  1. 19
    9
      src/components/shared/navBar.vue
  2. 0
    1
      src/components/user/loginPage.vue
  3. 2
    3
      src/store/modules/user/authentication.js

+ 19
- 9
src/components/shared/navBar.vue 查看文件

@@ -1,7 +1,7 @@
1 1
 <template>
2 2
   <!-- eslint-disable max-len -->
3 3
   <nav class="navbar navbar-default navbar-trans navbar-expand-lg fixed-top">
4
-    <div class="container-fluid">
4
+    <div class="container">
5 5
       <button
6 6
         class="navbar-toggler collapsed"
7 7
         type="button"
@@ -16,12 +16,6 @@
16 16
         <span></span>
17 17
       </button>
18 18
       <a class="navbar-brand text-brand" @click="routerGoTo('/')">
19
-        <img
20
-          class="img-fluid"
21
-          src="/img/logos/UVProp.png"
22
-          alt="Voasa Logo"
23
-          style="width:90px;height:45px;"
24
-        />
25 19
         Uni-Vate
26 20
         <span class="color-b">Properties</span>
27 21
       </a>
@@ -220,16 +214,32 @@
220 214
         <span class="fa fa-search" aria-hidden="true"></span>
221 215
       </button>
222 216
     </div>
217
+    <span v-if="showLogout">
218
+      <a @click="logout()">Logout</a>
219
+    </span>
220
+    <span v-else></span>
223 221
   </nav>
224 222
 </template>
223
+
225 224
 <script>
226
-import { mapGetters } from 'vuex';
225
+import { mapGetters, mapActions } from 'vuex';
227 226
 
228 227
 export default {
229
-  computed: {},
228
+  data() {
229
+    return {};
230
+  },
231
+  computed: {
232
+    showLogout() {
233
+      return this.$store.state.authentication.status === 'success';
234
+    },
235
+    Logout() {
236
+      return this.$store.state.authentication.methods.logout;
237
+    },
238
+  },
230 239
 
231 240
   methods: {
232 241
     ...mapGetters('authentication', ['isLoggedIn']),
242
+    ...mapActions('authentication', ['logout']),
233 243
 
234 244
     routerGoTo(goTo) {
235 245
       console.log(goTo);

+ 0
- 1
src/components/user/loginPage.vue 查看文件

@@ -59,7 +59,6 @@
59 59
           <p v-if="user !== null">{{ user }}</p>
60 60
         </div>
61 61
       </form>
62
-
63 62
       <form id="forgot">
64 63
         <div class="form">
65 64
           <h5>Trouble signing in?</h5>

+ 2
- 3
src/store/modules/user/authentication.js 查看文件

@@ -6,7 +6,7 @@ Vue.use(Vuex);
6 6
 export default {
7 7
   namespaced: true,
8 8
   state: {
9
-    status: '123',
9
+    status: '',
10 10
     token: localStorage.getItem('token') || '',
11 11
     user: {},
12 12
   },
@@ -28,7 +28,7 @@ export default {
28 28
     },
29 29
   },
30 30
   getters: {
31
-    isLoggenIn: state => !!state.token,
31
+    isLoggedIn: state => !!state.token,
32 32
     authStatus: state => state.status,
33 33
   },
34 34
   actions: {
@@ -59,7 +59,6 @@ export default {
59 59
     }) {
60 60
       return new Promise(() => {
61 61
         commit('logout');
62
-        console.log('What');
63 62
         localStorage.removeItem('token');
64 63
         delete axios.defaults.headers.common.Authorization;
65 64
       });

Loading…
取消
儲存