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

116
Views
Manejar el inicio de sesión con autenticación JWT en reactjs

estoy tratando de manejar el inicio de sesión con autenticación JWT y axios en mi aplicación reactjs; pero cada vez que envío mis datos al backend obtengo el error "'datos' no está definido no-undef"...

este es mi código de envío de identificador en Login.js:

 class Login extends Component{ constructor(props) { super(props); this.state = {username: "", password: ""}; this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } handleChange(event) { this.setState({[event.target.name]: event.target.value}); } handleSubmit(event) { event.preventDefault(); try { const response = axiosInstance.post('/token/obtain/', { username: this.state.username, password: this.state.password }); axiosInstance.defaults.headers['Authorization'] = "Bearer " + response.data.access; localStorage.setItem('access_token', response.data.access); localStorage.setItem('refresh_token', response.data.refresh); return data; } catch (error) { throw error; } } render() { return (...

y esto en mi archivo axiosInstance:

 const axiosInstance = axios.create({ baseURL: 'http://127.0.0.1:8000/', timeout: 5000, headers: { 'Authorization': "Bearer " + localStorage.getItem('access_token'), 'Content-Type': 'application/json', 'accept': 'application/json' } });

¿Cómo se puede manejar este error "'datos' no están definidos no-undef"????

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

0

creo que te estas perdiendo espera

 ... await axios.post(...

O puedes manejar así

 axios.post(...).then(response => { //response.data.access can be found here }

Pero, por supuesto, es mejor que verifique la documentación de axios y verifique qué es una Promesa.

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!