Closed IngridGdesigns closed 5 years ago
Need to work on delete users, user items and edit users, user items...
Finally got it to work, forgot to add the 'Content-Type': 'application/json' in the headers with the auth token. Like so :
const headers = { 'Authorization': Bearer ${this.props.auth.accessToken}
, 'Content-Type': 'application/json'}
let data = {
item_name: document.getElementById('itemInput').value,
}
fetch('http://localhost:3009/user_items', {
method: 'POST',
headers: headers,
body: JSON.stringify(data),
})
.then(res => res.json())
.then(response => this.setState({ user_items: [...this.state.user_items, response]}))
}
https://stackoverflow.com/questions/24543847/req-body-empty-on-posts
get post to work in React