问题描述
我尝试使用asyncstorage模块登录到我的后端api服务。这是代码:
const LoginScreen = (props) => {
const [username,setUsername] = useState('');
const [password,setPassword] = useState('')
const sendCred = async (props)=>{
fetch("http://10.0.2.2:3000/api/user/login",{
method:"POST",headers: {
'Content-Type': 'application/json'
},body:JSON.stringify({
"username":username,"password":password
})
})
.then(res=>res.json())
.then(async (data)=>{
try {
if(data){
await AsyncStorage.setItem('token',data.token)
console.log('data: ' + data.token);
props.navigation.replace("Home");
}else{
alert('Invalid username / password');
}
} catch (e) {
alert('Cannot get TOKEN');
console.log("error",e)
Alert(e)
}
})
}
它在第一次尝试时就可以工作,但是我不知道为什么现在我无法使用这种方法通过网络拒绝登录。有人可以告诉我怎么了吗?谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)