Home

Issue: 305

Access store or req obj in plugins

[issue link]

Hi,
I need to set the user’s token before making a request via axios.
Now axios is added as a plugin just like how it is shown in the docs.
The api’s are in another server which needs the users token. I need to add this to the authorisation header for every request like this

axios.defaults.headers.common['Authorization'] = 'JWT ' + token;

This token is present in the req obj and is added to the store via middleware. I can’t add it to the env because token is different for each user;

Is there any way to access the store or the req obj while a plugin is getting initialised? If not what are the other ways to achieve this

This question is available on Nuxt.js community (#c260)