|
1 | 1 |
|
2 | 2 | <script> |
3 | | - import { mapActions, mapState } from 'vuex' |
| 3 | + import { mapActions, mapGetters } from 'vuex' |
4 | 4 | import CcSpinner from '../general/spinner' |
5 | 5 | import { version } from '../../config' |
6 | 6 |
|
|
9 | 9 | CcSpinner, |
10 | 10 | }, |
11 | 11 | computed: { |
12 | | - ...mapState({ |
13 | | - user: state => state.Auth.user, |
14 | | - }), |
| 12 | + /** |
| 13 | + * See src/app/auth/vuex/getters.js |
| 14 | + */ |
| 15 | + ...mapGetters(['currentUser', 'isLogged']), |
15 | 16 | version() { |
16 | 17 | return version |
17 | 18 | }, |
18 | 19 | }, |
19 | | - methods: { |
20 | | - ...mapActions(['setToken', 'setUser']), |
21 | | - logout() { |
22 | | - this.setToken('') |
23 | | - this.setUser({}) |
24 | | - this.$router.push({ name: 'login.index' }) |
| 20 | + watch: { |
| 21 | + isLogged(value) { // isLogged changes when the token changes |
| 22 | + if (value === false) { |
| 23 | + this.$router.push({ name: 'auth.singin' }) |
| 24 | + } |
25 | 25 | }, |
| 26 | + }, |
| 27 | + methods: { |
| 28 | + /** |
| 29 | + * Makes logout() action available withint this component |
| 30 | + * See /src/app/auth/vuex/actions.js |
| 31 | + */ |
| 32 | + ...mapActions(['logout']), |
26 | 33 | /* eslint-disable no-undef */ |
27 | 34 | navigate(name) { |
28 | 35 | switch (name) { |
|
43 | 50 |
|
44 | 51 | <template> |
45 | 52 | <div> |
| 53 | + <cc-spinner></cc-spinner> |
46 | 54 | <el-menu theme="dark" default-active="1" class="cc-navigation" |
47 | 55 | mode="horizontal" @select="navigate"> |
48 | 56 | <el-menu-item index="codecasts" class="brand">Codecasts.com.br</el-menu-item> |
|
53 | 61 | <el-menu-item index="products.index">Products</el-menu-item> |
54 | 62 | </el-submenu> |
55 | 63 | <el-submenu index="menu-user" class="logout-button"> |
56 | | - <template slot="title">{{ user.name }}</template> |
| 64 | + <template slot="title">{{ currentUser.name }}</template> |
57 | 65 | <el-menu-item index="logout">Logout</el-menu-item> |
58 | 66 | </el-submenu> |
59 | 67 | </el-menu> |
|
64 | 72 | <style scoped> |
65 | 73 | .cc-navigation { |
66 | 74 | padding-left: 115px; |
| 75 | + padding-right: 30px; |
67 | 76 | } |
68 | 77 | .brand { |
69 | 78 | font-size: 1.2em; |
|
0 commit comments