I am trying to make a post request using axios in my react native code.
My backend is in Node.js and I am using Postman to test it out. Here, you can see that my endpoint aip/user/login sends back a token and id for the user with the email and password specified in the body.
My React Native code is the following :
export default function Signin(props) {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [isPasswordVisible, setIsPasswordVisible] = useState(false)
const login = () => {
// on teste le format de l'email
let isEmailValid = emailRegex.test(email);
if (isEmailValid) {
const user = {
email: email,
password: email
}
axios.post(`http://localhost:3002/api/user/login`, { user })
.then(response => {
console.log(response)
console.log(response.data)
})
.catch(error => console.log(error))
else {
alert("Email invalid")
}
}
return (
<View style={styles.container}>
<TextInput
label="Email"
value={email}
onChangeText={email => setEmail(email)}
/>
<View style={styles.password}>
<TextInput
label="Password"
value={password}
onChangeText={password => setPassword(password)}
/>
</View>
<Button mode="contained" onPress={login} style={styles.signin}> Signin</Button>
</View>
)
}
And this is the error I get. I don't even see the console.log(response) and the console.log(response.data) results. What am I doing wrong?


catch()handler on the promise. The error indicates that you've not created any rejection handling. - Emiel Zuurbier