davidedantonio / fastify-axios

Add axios http client to your fastify instance
MIT License
39 stars 4 forks source link

How to update bearer token in clients? #10

Closed vdvpie22 closed 2 years ago

vdvpie22 commented 3 years ago

When i use this construction:

fastify.register(require('fastify-axios'), {
    clients: {
      v1: {
        baseURL: 'https://v1.api.com',
        headers: {
          'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJxyz'
        }
      },
  })

how i can update headers before i send new request?

davidedantonio commented 2 years ago

Hi @vdvpie22 , you can use the transformRequest config to check if token is expired and update the headers. Let's take a look the axios documentation [https://axios-http.com/docs/req_config](axios documentation)