Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dennise89 opened this issue Jul 11, 2023 · 0 comments
Open

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

Dennise89 opened this issue Jul 11, 2023 · 0 comments

Comments

@Dennise89
Copy link

Dennise89 commented Jul 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant