lynndylanhurley / redux-auth

Complete token authentication system for react + redux that supports isomorphic rendering.
Do What The F*ck You Want To Public License
2.13k stars 260 forks source link

Passing request headers to every request #88

Open jesscarrasco opened 7 years ago

jesscarrasco commented 7 years ago

I am aware that I can use custom headers when using the fetch() function but I'd like to pass headers to the default API calls, for example when using email sign in. Is it possible?

yury-dymov commented 7 years ago

Hi @jesscarrasco, I am writing about redux-oauth, therefore I am not sure that solution will work for redux-auth but I assume it should.

You need to pass headers as options to fetch and headers should be merged with auth headers by library.

fetch(URL, {
   headers: {
       customerHeader: 'value'
   }
})

Another important part of the puzzle - your backend should support your custom headers, so you need to adjust your CORS configuration (which headers can be accepted and exposed) and probably nginx or whatever you use before your backend.

If redux-auth doesn't support merging custom headers this can be easily solved by small changes in library source code - check utils/fetch.js.