Reputation: 4596
I have below code in signout screen
await AsyncStorage.removeItem('userToken').then(()=>{
setTimeout(() => {
this.props.navigation.navigate('SignIn');
}, 3000);
On splash screen I am checking like this
const userToken = AsyncStorage.getItem('userToken').then(() => {
this.props.navigation.navigate(userToken ? 'App' : 'SignIn');
});
After signout Its redirect to sign-in, but when I open the app again splash screen moves to app rather than sign-in
My inital code was like
const userToken = AsyncStorage.getItem('userToken'), this.props.navigation.navigate(userToken ? 'App' : 'SignIn');
What I am doing wrong. Please advise.
Thanks
Upvotes: 2
Views: 2813
Reputation: 1625
i have implemented the same functionality like this
async logout() {
await AsyncStorage.clear();
Actions.SignIn(); // for navigating back to sign in screen if using router flux
this.props.navigation.navigate("SignIn"); // if using react-navigation
}
Upvotes: 0
Reputation: 308
If someone is still confused or finding the solution here
Then here is the solution :
const userToken = await AsyncStorage.getItem('userToken').then(() => {
this.props.navigation.navigate(userToken ? 'App' : 'SignIn');
});
Just add await
when you are getting a value of a key from AsyncStorage
I also had this problem BTW.
Upvotes: 0
Reputation: 305
Please check the file AndroidManifest.xml
and change android:allwoBackup=ture
to android:allwoBackup=false
. Hope this will work. When backup is true it always backup login information.
Upvotes: 0
Reputation: 951
Did you check the Async data result?
eg:
On splash screen
AsyncStorage.getItem("userToken").then(value => {
if(value) {
let token = JSON.parse(value);
this.props.navigation.navigate(token ? 'App' : 'SignIn');
} else {
this.props.navigation.navigate('SignIn');
}
});
Upvotes: 2
Reputation: 4961
You forget the param of callback,
const userToken = AsyncStorage.getItem('userToken').then((userToken) => {
this.props.navigation.navigate(userToken ? 'App' : 'SignIn');
});
Upvotes: 1