I'm having a bit of trouble setting up an API call for authentication in react native. I use the following code:
fetch('http://myserver.ngrok.io/auth/login', {
method: 'POST',
body: {
email: '[email protected]',
password: 'password',
},
})
.then(() => {
this.props.navigation.navigate('Main');
})
.catch(() => {
this.props.navigation.navigate('Auth');
console.error('Request Failed');
});
I'm using ngrok, because at first, I thought I was having issues with my android emulator/device QR scanning not being able to connect to my computer's localhost. I have tested the api call to this ngrok endpoint in postman, and it has worked perfectly. However, the above code always gives me my Request Failed.
I have tested this on both my android emulator and tunneling with my android phone via QR. Is this a syntax issue?
catch(console.log)so as to inspect and debug what error you're facing.