Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda