Nuxt.js: Access store or req obj in plugins

Created on 24 Feb 2017  路  3Comments  路  Source: nuxt/nuxt.js

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)
question

Most helpful comment

You should not set axios headers in the plugin because it change for every users.

All 3 comments

You should not set axios headers in the plugin because it change for every users.

@alexchopin Good to know that this will be added to the next version. When are you planning to release the next version?

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VincentLoy picture VincentLoy  路  3Comments

uptownhr picture uptownhr  路  3Comments

nassimbenkirane picture nassimbenkirane  路  3Comments

ghost picture ghost  路  3Comments

bimohxh picture bimohxh  路  3Comments