Search code examples
javascriptvue.jsvue-componentvuexvue-cli

Vue-auth accessing $auth inside vuex actions


I'm using Vue-auth package for authentication of my vue-cli application. Everything is working fine but when I'm accessing this code in my vue actions it returns undefined. any idea?

const AuthService = {
    test(data) {
        console.log(this.$auth)
    },
}

Package: https://github.com/websanova/vue-auth


Solution

  • You can access the auth instance of the package at Vue.auth property.

    import Vue from 'vue'
    
    const AuthService = {
        test(data) {
            console.log(Vue.auth)
        },
    }