Browse Source

add isStaff state to auth Vuex store

pull/1453/head
youichiro 3 years ago
parent
commit
147a1fe4fc
1 changed files with 11 additions and 1 deletions
  1. 12
      frontend/store/auth.js

12
frontend/store/auth.js

@ -1,7 +1,8 @@
export const state = () => ({
username: null,
id: null,
isAuthenticated: false
isAuthenticated: false,
isStaff: false
})
export const mutations = {
@ -16,6 +17,9 @@ export const mutations = {
},
setAuthenticated(state, isAuthenticated) {
state.isAuthenticated = isAuthenticated
},
setIsStaff(state, isStaff) {
state.isStaff = isStaff
}
}
@ -28,6 +32,9 @@ export const getters = {
},
getUserId(state) {
return state.id
},
isStaff(state) {
return state.isStaff
}
}
@ -46,13 +53,16 @@ export const actions = {
commit('setAuthenticated', true)
commit('setUsername', user.username)
commit('setUserId', user.id)
commit('setIsStaff', false)
} catch {
commit('setAuthenticated', false)
commit('setIsStaff', false)
}
},
async logout({ commit }) {
await this.$services.auth.logout()
commit('setAuthenticated', false)
commit('setIsStaff', false)
commit('clearUsername')
}
}
Loading…
Cancel
Save