Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding headers after axios instance is created #155

Closed
crofoot opened this issue Jan 18, 2020 · 2 comments
Closed

Adding headers after axios instance is created #155

crofoot opened this issue Jan 18, 2020 · 2 comments

Comments

@crofoot
Copy link

crofoot commented Jan 18, 2020

As the title says I was wondering if there is a way to add headers after an instance is created? So for example before the user authenticates I don't have an authorization header. But once they login I want to inject the authorization header into the current instance. Any help would be greatly appreciated!

@simoneb
Copy link
Owner

simoneb commented Jan 18, 2020

There are a few ways to do this. By default axios-hooks uses the default axios instance, which you can import anywhere else in code with import axios from 'axios'. In that case you can provide global defaults or even use an interceptor.

Another way would be to use a custom axios instance and configure axios hooks to use it, then use again the axios instance defaults or interceptors to add your header.

@crofoot
Copy link
Author

crofoot commented Jan 18, 2020

Thanks that worked! I had to add the header to the specific axios instance I created.

@crofoot crofoot closed this as completed Jan 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants