-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
storage.remove did not work well #204
Comments
Use only one storage instance in your app. Do not |
Alright, I try 1st. |
I have fixed it in another way, what have I done is after pressing the logout button, I try to restart the application by using RNRestart.Restart(); , then the data storage will been removed. https://github.com/avishayil/react-native-restart |
Are you using android 7+ devices and rn version < 0.57? |
And I did not get your logic flow. After you log out, the profile page will go to Login page immediately, then how can you see Wallet screen? Is there a tab or something, what is the route structure? And what do you mean by reopen the app and stay in wallet screen? If restart can solve the problem, then what is the difference between reopen and restart? |
I'm using API 26 and my rn version 0.57.7 |
For my case, the 1st page that the app will load is Wallet screen, in the Wallet will check the 'loginState', if there are any data inside 'loginState', then it will stay in Wallet screen, else, it will jump to login screen. |
After minimize and then reopen, why it is wallet screen but not login screen? Sounds like you started a new instance of your app. So maybe you need to modify your |
Ya, that's weird. I have tried to use console.log to trace and found that because in Wallet screen, the componentDidMount still can load the data from the storage, so that It won't go to login screen. |
Hi, I need some help here. The problem I faced is after pressing logout, the data in the storage has not been removed, unless I end task the app. So when I reopen the app, it will stay in my Wallet screen, it suppose will jump to my Login page.
My code is like this:
===================================================================
Wallet.js
var storage = new Storage({
size: 1000,
storageBackend: AsyncStorage,
defaultExpires: null,
enableCache: true,
sync: {
}
})
class Wallet extends Component {
...
componentDidMount(){
this.setState({Balance:""})
storage.load({
key: 'loginState',
autoSync: true,
}).then(result =>{
this._getWalletListbyToken(result.userEmail,result.userToken);
}).catch(error => {
switch(error.name){
case 'NotFoundError':
this.props.navigation.navigate("Login");
break;
case 'ExpiredError':
this.props.navigation.navigate("Login");
break;
}
})
}
_CheckUserIsLoggedBefore = (email, token) => {
if(token == null){
this.props.navigation.navigate("Login");
}
}
...
}
===================================================================
Login.js
var storage = new Storage({
size: 1000,
storageBackend: AsyncStorage,
defaultExpires: null,
enableCache: true,
sync: {
}
})
class Login extends Component {
...
loginMainPage = () => {
}
}
===================================================================
Profile.js
var storage = new Storage({
size: 1000,
storageBackend: AsyncStorage,
defaultExpires: null,
enableCache: true,
sync: {
}
})
class Profile extends Component {
...
onLogOutPressed = () => {
storage.remove({
key: 'loginState',
})
.then(()=>{
this.props.navigation.navigate("Login");
})
.catch((error)=>{
}
render() {
return (
<TouchableOpacity style={styles.buttonContainer} onPress={()=> this.onLogOutPressed()}>
<LogoutIcon style={{fontSize:18, color: color.gold, marginRight:5, marginLeft:-10 }} name='logout'/>
{this.props.languageContent.logout}
)
}
}
The text was updated successfully, but these errors were encountered: