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

76
Vistas
store token in cookie or local storage in reactjs

I have a reactjs login application and I want to store the token I get from the API to cookie or local storage, the code below is the basic authentication POST method that I use. can you show me how to store token in the cookie or local storage in reactjs? Which one is better?

  const xhr = new XMLHttpRequest();
    const data = "access_token=value";
    const url = "https://api";
    xhr.open("POST", url);
    xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    xhr.setRequestHeader(
      "Authorization",
      "Basic " + btoa("Username:Password")
    );
    xhr.send(data);
    xhr.onreadystatechange = () => {
      if (xhr.readyState === XMLHttpRequest.DONE) {
        console.log(xhr.response);
      }
    };

my response has a token parameter and the value of it.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Generally in web app, we used a localstorage or session to our token id in our web app. so, you can used localstorage or session. based on your project requirement you can used any one.

Exmple

localStorage.setItem('variableName', data);

you can save this way in localstorage.

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