Use auth store

This commit is contained in:
Hubert Van De Walle 2020-06-09 16:39:40 +02:00
parent 48bfbe80fe
commit e22f774385
2 changed files with 15 additions and 22 deletions

View File

@ -17,17 +17,18 @@
</template> </template>
<v-list> <v-list>
<client-only> <v-list-item
<v-list-item v-if="isAuthenticated" to="/notes"> v-if="loggedIn && !$route.path.includes('/notes')"
to="/notes"
>
My notes My notes
</v-list-item> </v-list-item>
<v-list-item v-if="isAuthenticated" @click="logout"> <v-list-item v-if="loggedIn" @click="logout">
Logout Logout
</v-list-item> </v-list-item>
<v-list-item v-else> <v-list-item v-else>
<v-btn to="/account" text rounded>Account</v-btn> <v-btn to="/account" text rounded>Account</v-btn>
</v-list-item> </v-list-item>
</client-only>
</v-list> </v-list>
</v-menu> </v-menu>
</v-app-bar> </v-app-bar>
@ -35,7 +36,7 @@
<script> <script>
import { mdiDotsVertical, mdiBrightness5, mdiBrightness2 } from '@mdi/js' import { mdiDotsVertical, mdiBrightness5, mdiBrightness2 } from '@mdi/js'
import { mapGetters } from 'vuex' import { mapState } from 'vuex'
export default { export default {
name: 'Navbar', name: 'Navbar',
@ -45,7 +46,7 @@ export default {
mdiBrightness2, mdiBrightness2,
}), }),
computed: { computed: {
...mapGetters(['isAuthenticated', 'loggedInUser']), ...mapState('auth', ['loggedIn']),
}, },
methods: { methods: {
async logout() { async logout() {

View File

@ -4,12 +4,4 @@ export const mutations = {}
export const actions = {} export const actions = {}
export const getters = { export const getters = {}
isAuthenticated(state) {
return state.auth.loggedIn
},
loggedInUser(state) {
return state.auth.user
},
}