Hi,
I'm currently trying to fetch a jwt-token from a response from my api.
The response looks like this:
{
"message": "Auth successful",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IlRvbUB0b20uZGUiLCJ1c2VySWQiOiI1ZGZiZTdiMWI3OTZkOTU4NzBiMGM4M2MiLCJpYXQiOjE1NzkyODg1NjYsImV4cCI6MTU4MTk2Njk2Nn0.7EmFE1D7wwqysPNkMMwiiw447TZiXy3kkqsXbyF1fDc"
}
Now I'm trying to fetch the token out of that response in that function:
_signInAsync = async() => {
if(this.state.email !== '' && this.state.password!== ''){
fetch('http://192.168.2.60:4563/login', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: this.state.email,
password: this.state.password,
}),
})
.then((response) => {
if(response.ok){
console.log(this.state.email);
this.props.navigation.navigate('Main');
}
})
}
};
_signInAsync function is called via a button I have created. After severel tries with different approaches I couldn't figure out the right way, so now I'm hoping for your help!
Greetings from Berlin!
.then()when you can justconst response = await fetch(...)