Browse Source
Merge pull request #680 from tusharmakkar08/master
Added username in localstorage
pull/722/head
Hiroki Nakayama
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
8 additions and
4 deletions
-
frontend/components/organisms/layout/TheHeader.vue
-
frontend/store/auth.js
|
|
@ -67,7 +67,7 @@ |
|
|
|
</v-btn> |
|
|
|
</template> |
|
|
|
<v-list> |
|
|
|
<v-subheader>{{ username }}</v-subheader> |
|
|
|
<v-subheader>{{ getUsername }}</v-subheader> |
|
|
|
<v-list-item @click="signout"> |
|
|
|
<v-list-item-icon> |
|
|
|
<v-icon>mdi-logout</v-icon> |
|
|
@ -84,7 +84,7 @@ |
|
|
|
</template> |
|
|
|
|
|
|
|
<script> |
|
|
|
import { mapGetters, mapActions, mapState } from 'vuex' |
|
|
|
import { mapGetters, mapActions } from 'vuex' |
|
|
|
import TheColorModeSwitcher from '@/components/organisms/layout/TheColorModeSwitcher' |
|
|
|
|
|
|
|
export default { |
|
|
@ -104,8 +104,7 @@ export default { |
|
|
|
}, |
|
|
|
|
|
|
|
computed: { |
|
|
|
...mapGetters('auth', ['isAuthenticated']), |
|
|
|
...mapState('auth', ['username']) |
|
|
|
...mapGetters('auth', ['isAuthenticated', 'getUsername']) |
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
|
|
@ -25,6 +25,9 @@ export const mutations = { |
|
|
|
export const getters = { |
|
|
|
isAuthenticated(state) { |
|
|
|
return state.token != null |
|
|
|
}, |
|
|
|
getUsername() { |
|
|
|
return localStorage.getItem('username') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -35,6 +38,7 @@ export const actions = { |
|
|
|
commit('setToken', result.data.token) |
|
|
|
commit('setUsername', authData.username) |
|
|
|
localStorage.setItem('token', result.data.token) |
|
|
|
localStorage.setItem('username', authData.username) |
|
|
|
Cookie.set('jwt', result.data.token) |
|
|
|
ApiService.setHeader(result.data.token) |
|
|
|
}) |
|
|
@ -64,6 +68,7 @@ export const actions = { |
|
|
|
Cookie.remove('jwt') |
|
|
|
if (process.client) { |
|
|
|
localStorage.removeItem('token') |
|
|
|
localStorage.removeItem('username') |
|
|
|
} |
|
|
|
} |
|
|
|
} |