My login code was working properly when I was using react-native-0.41.2
and react-15.4.2
. Now I have upgraded react-native to 0.52
and react 0.16.2
. But now API is not giving any response when I tried to login into the app.
I also tried to make some changes in Info.plist file keys but it didn't work. Please provide me any suggestion for it.
class Login extends React.Component {
login(e) {
e.preventDefault();
var user = '';
var pass = '';
user = this.state.username;
pass = this.state.password;
this.authenticate(user, pass);
return;
}
async authenticate(username, password) {
let _this = this;
Api.login(username, password)
.then(async response => {await response.json()})
.then(async response => {
//My code
});
}
render() {
let { username, password } = this.state;
return (
<View >
<TextField
label='username'
value={username}
autoCapitalize= 'none'
onChangeText={ (username) => this.setState({ username }) }
/>
<TextField
label='password'
value={password}
secureTextEntry autoCapitalize= 'none'
onChangeText={ (password) => this.setState({ password }) }
style={{marginBottom: 10}}
/>
<TouchableOpacity style={styles.loginButtons} onPress={(e) =>
this.login(e)}>
<Text style={styles.buttonText}> Login </Text>
</TouchableOpacity>
</View>
);
}
}
My api code -
login(username, password) {
let url = '/api/sessions';
return fetch(BASE_URL + url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
user: {
email: username,
password: password
}
})
});}