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?