flutter_secure_storage icon indicating copy to clipboard operation
flutter_secure_storage copied to clipboard

Data is not removed when user uninstall the IOS app but its working fine in Android side.

Open MohsinIkram777 opened this issue 8 months ago • 9 comments

I'm saving user credentails in the secure stoage and when user unistall the app without logout then install the app again then the excepted behaivor is user moved to login screen because all data cleared when user uniinstall the app.

But its not working in IOS side. User is going to dashboard screen as data is not cleared. But In Android side its working great. User moved to login screen.

Let me know if you have fixed it in the any latest version or any proper solution you have? Need your swift response we are going to live in this week. Thanks

MohsinIkram777 avatar Mar 03 '25 05:03 MohsinIkram777

I have same problem. Have you found any solution?

KrsticM avatar Mar 14 '25 15:03 KrsticM

Keychain data can persist across app uninstalls unless explicitly cleared, whereas Android typically wipes all app-associated data, including secure storage, upon uninstallation. I’ve encountered a similar issue before and resolved it by implementing a simple workaround. The solution involves using a flag stored in shared preferences (or a similar lightweight storage mechanism) to detect whether the app has been reinstalled.

  1. When the app is first installed or launched, set a flag (e.g., isAppInstalled) in shared preferences.
  2. On app start, check if the flag exists.
  3. If missing (reinstall detected), manually clear all data with deleteAll
  4. Set the flag again after clearing.

diipak-singh avatar Mar 21 '25 10:03 diipak-singh

@diipak-singh yeah, I have already implemented this solution. I'm clearning the auth on the basis of that flag. Thanks for your input.

MohsinIkram777 avatar Mar 21 '25 10:03 MohsinIkram777

@KrsticM I have fixed by this code -> just add this dependency into pubspecs file-> shared_preferences

and call this method into the Main.dart file

clearSecureStorageOnReinstall() async {
  String key = 'hasRunBefore';
  SharedPreferences prefs = await SharedPreferences.getInstance();

  if (!(prefs.getBool(key) ?? false)) {
    await UserPreferences.logoutUser(); //Remove auth credentails here
    prefs.setBool(key, true);
  }
}

MohsinIkram777 avatar Mar 21 '25 11:03 MohsinIkram777

@KrsticM I have fixed by this code -> just add this dependency into pubspecs file-> shared_preferences

and call this method into the Main.dart file

clearSecureStorageOnReinstall() async {
  String key = 'hasRunBefore';
  SharedPreferences prefs = await SharedPreferences.getInstance();

  if (!(prefs.getBool(key) ?? false)) {
    await UserPreferences.logoutUser(); //Remove auth credentails here
    prefs.setBool(key, true);
  }
}

you should also delete the data as well from flutter secure storage if you find out that app is fresh installed something like FlutterSecureStorage().deleteAll(iOptions: _getIOSoptions())

diipak-singh avatar Mar 21 '25 11:03 diipak-singh

Any update on this? As this is a security risk if we use any third party tools for testing purpose.

akrutipanchal avatar Mar 28 '25 12:03 akrutipanchal

I'm not sure if there's anything a plugin can do AFAIK there's no way to run an action "on app uninstall", iOS doesn't provide such a callback And iOS keeps all values in the keystore when the app is uninstalled - it's an iOS feature Only shared preferences & app's files are cleared on uninstall You can implement your own encryption and store sensitive values in encrypted form in shared preferences, or in a separate file in app's data directory, but this seems out of scope of this package

Android doesn't have a system-wide keystore, which is why it isn't an issue there It has nothing to do with the package itself

vanyasem avatar Apr 15 '25 10:04 vanyasem

See https://stackoverflow.com/questions/4747404/delete-keychain-items-when-an-app-is-uninstalled for more details

vanyasem avatar Apr 18 '25 11:04 vanyasem

This issue should be as important notice on readme in case it won't be fixed.

Maybe the package can be able to handle this by using UserDefaults on iOS, so it set's the hasRunBefore flag and clear the Keychain values when the flag wasn't found.

hectorAguero avatar May 30 '25 17:05 hectorAguero

⚠️ This issue has been marked as stale because it has been open for 60 days with no activity.

If this issue is still relevant, please comment to keep it active. Otherwise, it will be closed in 60 days.

github-actions[bot] avatar Jul 30 '25 03:07 github-actions[bot]