I'm fetching an API, and it's work well. But in this case resp is always null. I'm wondering how to affect the result of this post request to the resp var.
var resp = null
fetch('http://a1a239a6.ngrok.io/api/login', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: "email=" + email + "&password=" + password,
}).then((response) => response.json())
.then((responseJson) => resp = responseJson)
.catch((error) => console.error(error))
if (resp != null) {
navigate('Welcome', {
user: resp
})
console.log(resp)
}