dgrubelic / vue-authenticate

Simple Vue.js authentication library
1.43k stars 251 forks source link

Cannot read property 'authenticate' of undefined #138

Open vishalmindinventory opened 6 years ago

vishalmindinventory commented 6 years ago

@dgrubelic Below is my code for twitter integration. I am using SSR with webpack.

login.vue `<b-link class="tw" @click="auth('twitter')"> Twitter

export default { methods: { auth: function (provider) { this.$auth.authenticate(provider).then(function () { console.log("in") }) }, } }`

app.js `if (typeof window !== 'undefined') { const VueAuthenticate = require('vue-authenticate')

Vue.use(VueAuthenticate, {
    tokenName: 'access_token',
    baseUrl: 'http://localhost:3003/',
    storageType: 'localStorage',
    providers: {
        twitter: {
            name: 'twitter',
            url: '/auth/twitter',
            authorizationEndpoint: 'https://api.twitter.com/oauth/authenticate',
            redirectUri: window.location.origin,
            oauthType: '1.0',
            popupOptions: { width: 495, height: 645 }
        }
    }
})

}`

Version history Node version: 10.11.0 npm version: 6.2.0 vue version: 3.0.0 webpack: 3.8.1

I had used condition because, I am getting error i.e. window is not defined. Let me if anything is missing.

Thanks in advance.

dgrubelic commented 6 years ago

I believe that the issue is in a way you define Vue component method. It should be like this:

export default {
  methods: {
    auth(provider) {
      this.$auth.authenticate(provider) { ... };
    }
  }
}

As for SSR support, this will be provided in next release.

vishalmindinventory commented 6 years ago

Ok. Thanks!