Skip to content

Commit

Permalink
Implemented signout functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
anoobbava committed Sep 13, 2019
1 parent cbdc80d commit e9bffa0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<div class="flex-grow-1"></div>
<v-toolbar-items v-if="isLoggedIn">
<v-btn text >Add Todo</v-btn>
<v-btn text >SignOut</v-btn>
<v-btn text
@click="logoutAction"
>SignOut</v-btn>
</v-toolbar-items>

<v-toolbar-items v-else>
Expand All @@ -20,14 +22,16 @@
</template>

<script>
import { mapGetters } from 'vuex'
import { mapGetters, mapActions } from 'vuex'
export default {
computed: {
...mapGetters(['isLoggedIn'])
},
methods: {
...mapActions(['logoutAction']),
redirectToHome () {
this.$router.push('/')
},
Expand Down
11 changes: 11 additions & 0 deletions src/store/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export default {
state.status = 'failure'
state.token = ''
state.user = {}
},

logoutMutation (state) {
state.user = ''
state.token = ''
state.status = null
}
},

Expand Down Expand Up @@ -54,6 +60,11 @@ export default {
reject(error)
})
})
},

logoutAction ({ commit }) {
commit('logoutMutation')
localStorage.removeItem('token')
}
},

Expand Down
7 changes: 5 additions & 2 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<template>
<div>
<h3>welcome to home</h3>
<h3>welcome {{this.userName}}</h3>
</div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
computed: {
...mapGetters(['userName'])
}
}
</script>

0 comments on commit e9bffa0

Please sign in to comment.