SohoHouse / nuxt-oauth

Simple OAuth2 integration for your Nuxt app
MIT License
123 stars 27 forks source link

Getting Axios ot Vuex Store in the fetchUser method #13

Closed bahek2462774 closed 6 years ago

bahek2462774 commented 6 years ago

How can I get access to the axios or vue store inside this method fetchUser?. Or how am I supposed to implement fetching user? Thanks!

samtgarson commented 6 years ago

To get axios you can just import it at the top of your nuxt.config.js:

// nuxt.config.js
const { get } = require('axios')

module.exports = {
  oauth: {
    fetchUser: async token => {
      const { data } = await get(`https://my.api.com/me?token=${token}`)
      return data
    }
  }
}

I'm not sure it's possible to get access to the vue store, as this whole thing happens on the server before the Vue instance is even created and before nuxt is initialised.

If you can give me some more information about your situation maybe I can help more 👍

bahek2462774 commented 6 years ago

It's enough. Thanks a lot!