Skip to content
Snippets Groups Projects
AuthWall.vue 1.04 KiB
Newer Older
  • Learn to ignore specific revisions
  • Richard Blechinger's avatar
    Richard Blechinger committed
        <div
    
            v-if="$store.state.auth.user.steeringUser"
            class="tw-w-full"
        >
    
    Richard Blechinger's avatar
    Richard Blechinger committed
            <slot />
    
    Richard Blechinger's avatar
    Richard Blechinger committed
        <div
    
            v-else
            class="tw-w-full tw-text-center"
        >
    
            {{ $t('loading') }}
        </div>
    </template>
    
    <script>
        export default {
            created() {
    
                const user = this.$store.state.auth.user.steeringUser
    
    
                // We might not have a user at load-time.
                // In this case wait until the store gives us one.
                if (user === null) {
                    this.$store.watch(
                        (state) => state.auth.user.steeringUser,
                        (user) => this.redirectToHome(user)
                    )
    
    
                    return
    
                this.redirectToHome(user)
    
            },
    
            methods: {
                redirectToHome(user) {
                    if (!user.is_superuser) {
    
                        this.$toast.error(this.$t('auth.permissionError'))
    
                        this.$router.push({name: 'home'})