byjove/src/plugin.js

36 lines
1 KiB
JavaScript
Raw Normal View History

export function ByjovePlugin(Vue) {
Vue.mixin({
methods: {
$loginUser(user) {
// put user info in app store
this.$store.commit('SET_USER', user)
this.$store.commit('SET_USER_IS_ADMIN', user.is_admin)
// note, this should already be false
// this.$store.commit('SET_USER_IS_ROOT', false)
},
$logoutUser() {
// remove user info from app store
this.$store.commit('SET_USER', null)
this.$store.commit('SET_USER_IS_ADMIN', false)
this.$store.commit('SET_USER_IS_ROOT', false)
},
$hasPerm(name) {
// if user is root then assume permission
if (this.$store.state.user_is_root) {
return true
}
// otherwise do true perm check for user
return this.$store.state.permissions.includes(name)
},
}
})
}