Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
Axios Config with Auth Header, best practise?

I am setting up JWT authentication, everything is working fine but I got stuck at the last piece where I am not sure what I should do.

I have set up my Axios Config as this:

const token = ""

export const axios = Axios.create({
    baseURL: "http://localhost:8080",
    headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${token}`
      },
});

so here are few problems I have ..

  1. if I want to log in, I need to have the "Auth" field to be gone, since I am not sending any cookie, if I do so, my backend fires an Exception since the cookie is not complete
  2. How should I go about the Axios config, should I fill the "token" variable OR should I work here with the cookie in the local storage?
  3. Is it a good practice to have multiple configs and use them simultaneously depending on the situation?

hope anyone can help me out! :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For anyone coming accross this question, to handle such situations i use axios.interceptors which let you access a certain event inbetween the request and response, that way you can handle the Auth Token and also in case of the "need" to refresh the token, it also should be handled here.

Multiple Axios Configs are also a way to go, but not necessary for that case, pointing out here.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!