Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Created February 6, 2018 19:33
Show Gist options
  • Select an option

  • Save VitorLuizC/22b207c55359982830ba0cc7c6c41149 to your computer and use it in GitHub Desktop.

Select an option

Save VitorLuizC/22b207c55359982830ba0cc7c6c41149 to your computer and use it in GitHub Desktop.
<template lang="pug">
router-view(v-if="user !== undefined")
</template>
<script>
import { mapGetters } from 'vuex'
import { authentication } from '../lib/authentication.js'
export default {
computed: {
...mapGetters(['user', 'profile'])
},
created() {
authentication.onAuthStateChanged(async user => {
await this.$store.commit('update-user', user || null)
let permission = (this.$route.meta.profiles.indexOf(this.profile) > -1)
if (!permission) {
let isGuest = (this.profile === 'guest')
this.$router.replace(isGuest ? '/login' : '/dashboard')
}
})
}
}
</script>
<style lang="stylus">
@import '../style/base.styl'
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment