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

160
Vistas
Bad request when trying to retrieve data from server using Axios

I'm just learning how to use Axios and I'm trying to retrieve the username stored in a jwt from the server. However, I'm getting ERR_BAD_REQUEST and I'm not sure as to why.

Below is the request I make to the server

useEffect(() => {
    Axios.post('localhost:3001/api/getuserdata', {
       token: localStorage.getItem('token')
    }).then((response) => {
      setUsername("/home/" + response.username)
      console.log(username)
    })
  }, [])
  

This is the how the server handles the request

app.post('/api/getuserdata'), async (req, res) => {
    const token = req.body.token;
    const decoded = jwt.verify(token, '<My Password>')
    const username = decoded.username
    return res.json({username: username})
}

From what I can tell this should be setting the username but it's always a bad request. What am I missing?

about 4 years ago · Juan Pablo Isaza
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