if(userLoggedin) {
console.log(userLoggedin);
navigation.replace('DrawerNavigationRoutes');
return ( <View>
<Text> hello </Text>
</View>)
}
else{
console.log('login screen');
console.log(userLoggedin);
return (
<View>
<Text> Login screen </Text>
</View>) )
登录屏幕显示延迟后关闭并进入个人资料页面。
一旦用户登录,我的用户如何到达配置文件页面。
const response = await fetch(
'http://3.108.170.236/erp/apis/login_otp.php',
requestOptions,
);
//const response1 = await fetch('https://webhook.site/4326abbc-7ec9-
41d0-b967-ad888f79c33a', requestOptions);
console.log('Otp fetched');
const json_data = await response.json();
console.log(json_data);
const userdetails= await AsyncStorage.getItem("Otp_details");
const details = JSON.parse(userdetails);
const otp_valued = details[0].otp_value;
const student_idd = details[0].student_id;
setMyotp_value('123');
setMyotp_value(otp_valued);
setMystudent_id(student_idd);
console.log(myotp_value);
console.log(userOtp);
if(myotp_value==userOtp){
console.log('OTP verified');
navigation.replace('DrawerNavigationRoutes');
return null;
}
else
{
console.log('otp mismatched');
}
帮助获取值我不是第一次获得otp_value时Touch second time数据与asyncstorage进行比较。
/////////////////////////获取数据 //////////////////////////////
try {
let value = await AsyncStorage.getItem('Otp_details');
if (value != null)
{
// do something
console.log('User mobile Otp verified');
setUserLoggedin(true);
// navigation.replace('DrawerNavigationRoutes');
}
else
{
// LoginScreen;
// return null;
}
} catch (error) {
// Error retrieving data
}
首先需要将登录数据存储在AsyncStorage中点击登录按钮后:=>
import AsyncStorage from '@react-native-async-storage/async-storage';
const loginfun = async (userData) => {
await AsyncStorage.setItem('@logData', userData)
// pass your desired screen here
}
如果你想检查保存的数据,你可以…
const checkDataFun = async () => {
const data = await AsyncStorage.getItem('@logData');
console.log(data +"......data")
}