Search code examples
axiosnestjs

How Set authorization token dynamically to request in Axios, NestJs


How to set the authorization token dynamically to Axios per each request? Axios is used for requests forwarded from service to external services.


Solution

  • You can add it to the headers via the options parameter

    const res = await axios.get('https://httpbin.org/get', {
      headers: {
        'Authorization': 'Bearer ey…'
      }
    });