Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda