React native 如何在React Native中进行API登录身份验证
我不确定如何使用电子邮件和密码进行基本的api登录验证。我被困在这里了。如果有人能帮忙。这是我的密码:React native 如何在React Native中进行API登录身份验证,react-native,api,authentication,React Native,Api,Authentication,我不确定如何使用电子邮件和密码进行基本的api登录验证。我被困在这里了。如果有人能帮忙。这是我的密码: class LoginScreen extends Component { constructor(){ super(); this.state = { email: '', password: '', result: false, }
class LoginScreen extends Component {
constructor(){
super();
this.state = {
email: '',
password: '',
result: false,
}
}
_userLogin() {
var email = this.state.username;
var password = this.state.password;
if (email && password) { // if validation fails, value will be null
fetch("https://URL/api/login", {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: email,
password: password,
})
})
.then((response) => response.json())
.then((responseData) => {
console.log(responseData);
AlertIOS.alert(
"Login Success!"
),
this._onValueChange(STORAGE_KEY, responseData.id_token)
})
.done();
renderResults();
}
}
handleEmail = (text) => {
this.setState({ email: text })
}
handlePassword = (text) => {
this.setState({ password: text })
}
然后是如何在输入字段和按钮中使用它。请在问题中添加更多详细信息提及您需要做什么我需要进行基本的api登录验证,需要有人向我演示如何使用,我不确定这是否有效。然后,如何在电子邮件/传递字段和按钮中使用它您使用的导航库是什么?React navigation嘿,搜索带有一些用户登录功能的基本React本机教程。如果你对具体细节有疑问,可以在这里询问。