'login screen is showed but i want to show profile page with help of async storage

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>) )

login screen is showing after delaying it goes off and take to profile page.

What to do how my user reach profile page if once is user logged in.

  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');
   }

help to get the value i am not geting the otp_value for first time when touch second time data is compared with the asyncstorage.

///////////////////////// getting data //////////////////////////////

 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
}


Solution 1:[1]

First you need to store login data in AsyncStorage after clicking on the login button :=>

import AsyncStorage from '@react-native-async-storage/async-storage';


const loginfun = async (userData) => {
    await AsyncStorage.setItem('@logData', userData)
  // pass your desired screen here 
}

if you want to check saved data you can ...

const checkDataFun = async () => {
  const data = await AsyncStorage.getItem('@logData');
  console.log(data +"......data")
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AshishVE