Closed aslam closed 7 years ago
Hi. Thanks for report. As a workaround would you please try this :
modules: [
'@nuxtjs/pwa',
'@nuxtjs/component-cache',
['@nuxtjs/axios', {
requestInterceptor (config, { store }) {
if (store.state.auth.accessToken) {
config.headers.common['Authorization'] = store.state.auth.accessToken
}
return config
}
}]
]
@pi0 thanks for the reply. No luck:
modules: [
'@nuxtjs/pwa',
'@nuxtjs/component-cache',
['@nuxtjs/axios', {
baseURL: 'https://now-staging.syedaslam.com/',
requestInterceptor (config, { store }) {
if (store.state.auth.accessToken) {
config.headers.common['Authorization'] = store.state.auth.accessToken
}
return config
}
}]
]
p.s.: tried with and without baseURL.
This is the same problem as: https://github.com/nuxt/nuxt.js/issues/723
We used the same code as above and have the same problem.
I am thinking about clean solution. Any idea? https://runkit.com/pi0/591db24aff32a300123e931a
@awronski Actually serialization of functions is a REAAL headache but unavoidable :)))
One possible solution would be serialized as is without adding a function before or maybe parse the string and replace function
to `` just on the first line.
Hi! @pi ,
The first version of the fork was serializing as it is but then named function was not working :( https://github.com/nuxt-community/modules/pull/100#issuecomment-318888180
We fixed it and now it is not working with the babel :)
Maybe the only solution is to hack it as you suggest.
@pi0, @awronski
The solution of giving a different name to the function as in the last comment by @slevp in https://github.com/nuxt/nuxt.js/issues/723 worked for me (at least in dev):
modules: [
'@nuxtjs/pwa',
'@nuxtjs/component-cache',
['@nuxtjs/axios', {
baseURL: 'https://now-staging.syedaslam.com/',
requestInterceptor: function _reqInterceptor (config, { store }) {
if (store.state.auth.accessToken) {
config.headers.common['Authorization'] = store.state.auth.accessToken
}
return config
}
}]
]
should be fixed with #108 please upgrade to "@nuxtjs/axios" : "^3.1.2"
Following the docs I am trying to add the request interceptor to include the Authorization token:
nuxt.config.js
However, this throws up an error while building:
I am using
backpack
for my builds, the following is mypackage.json
I think I am using the compatible packages. Is there something I am doing wrong in the config or the way I am trying to add the interceptor?