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

Add authorization in request header #301

Open
anatel opened this issue Mar 11, 2019 · 5 comments
Open

Add authorization in request header #301

anatel opened this issue Mar 11, 2019 · 5 comments

Comments

@anatel
Copy link

anatel commented Mar 11, 2019

Is it possible to configure the request header and add authorization token before it is sent?

@jamuhl
Copy link
Member

jamuhl commented Mar 12, 2019

good catch...should have documented those options: https://github.com/i18next/i18next-xhr-backend/blob/master/src/ajax.js#L55

  // custom request headers sets request.setRequestHeader(key, value)
  customHeaders: {
    authorization: 'foo',
    // ...
  },

@anatel
Copy link
Author

anatel commented Mar 12, 2019

Thanks,
I have a token that can change from one call to another, so I can't just pass a string, i want to pass it something dynamic, maybe a function.

I understand that loadPath can get a function, can customHeaders get a function as well?

Or is there any way to change this middleware's config after the init phase?

@jamuhl
Copy link
Member

jamuhl commented Mar 12, 2019

You should be able to modify backend.options, something like:

i18next.services.backendConnector.backend.options.customHeaders = { .... }

@anatel
Copy link
Author

anatel commented Mar 12, 2019

Great, thanks!

@MatthewTrout
Copy link
Contributor

This still isn't ideal, could it be made to accept a headers function also? Trying to make this as declarative as possible..

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

3 participants