williamcruzme / vue-gates

🔒 A Vue.js & Nuxt.js plugin that allows you to use roles and permissions in your components or DOM elements, also compatible as middleware and methods.

Home Page:https://williamcruzme.github.io/vue-gates/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

this.$gates is not defined in Vue3 with Pinia installed

Dennise89 opened this issue · comments

Hello,

I'm trying to access this.$gates.setRoles([...roles]) inside my pinia store, but I'm getting the error TypeError: Cannot read properties of undefined (reading 'setRoles')

import {defineStore} from "pinia";
import axios from 'axios';

export const useUserStore = defineStore("UserStore", {
    state: () => {
        return {
            user: [],
            authenticated: false,
        }
    },
    actions: {
        async fill() {
            try {
                const res = await axios.get('v1/user');
                if (res) {
                    this.user = res.data
                    this.authenticated = true
                    try {
                        this.$gates.setRoles(res.data.roles)
                    } catch (e) {
                        console.log(e)
                    }
                }
            } catch (err) {
                this.user = []
                this.authenticated = false
            }
        }
    }
});

I've also tried with Vue.prototype.$gates, but that does not work either.
I've tried to import VueGates at the top, but that did not work either.

Documentation is really bare and should be improved.