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

188
Views
¿Cómo puedo almacenar mi token JWT en userInfo?

Intenté muchas cosas pero no puedo continuar... Me atasqué... Si inicio sesión en mi cuenta, funciona, también obtengo mi información de usuario, pero solo mi ID de usuario y mi contraseña... pero también tendría mi token. .

Escribí un estado if donde atrapo mi token, pero quiero configurarlo también en el almacenamiento local y no sé cómo hacerlo.

 export const login = (userID, password) => async (dispatch) => { try { dispatch({ type: USER_LOGIN_REQUEST }); const url = "http://localhost:8080/authenticate/"; const config = { auth: { username: userID, password, }, }; const data = {}; const response = await axios.post( url, data, config, ) dispatch({ type: USER_LOGIN_SUCCESS, payload: config}); //localStorage.setItem("userInfo", JSON.stringify(config) ); if (response.status === 200) { // Login succeeded const token = response.data.token; console.log("TOKEN\n" + token); localStorage.setItem("userInfo", JSON.stringify(config) ); } } catch (error) { //alert("Sorry, login failed"); dispatch({ type: USER_LOGIN_FAIL, payload: error.response && error.response.data.ErrorMessage ? error.response.data.ErrorMessage : error.message, }); } };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

prueba esto

 export const login = (userID, password) => async (dispatch) => { try { dispatch({ type: USER_LOGIN_REQUEST }); const url = "http://localhost:8080/authenticate/"; const config = { auth: { username: userID, password, //this should not be saved in your local storage delete this from here }, }; const data = {}; const response = await axios.post( url, data, config, ) dispatch({ type: USER_LOGIN_SUCCESS, payload: config}); if (response.status === 200) { // Login succeeded config.token = response.data.token; } localStorage.setItem("userInfo", JSON.stringify(config) ); } catch (error) { //alert("Sorry, login failed"); dispatch({ type: USER_LOGIN_FAIL, payload: error.response && error.response.data.ErrorMessage ? error.response.data.ErrorMessage : error.message, }); } };
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!