mogol / flutter_secure_storage

A Flutter plugin to store data in secure storage
https://pub.dartlang.org/packages/flutter_secure_storage
BSD 3-Clause "New" or "Revised" License
1.12k stars 367 forks source link

Weird issue where for iOS only #614

Closed curtis2101 closed 1 month ago

curtis2101 commented 1 year ago

There is an issue where the top line of a storeAndOverwrite function is saved and able to be read when the app is running. But on restart of the app the top line that was written could not be found at all. This happens only on IOS and to fix this I Have added a future delay for now. So in this example without a delay the biometric preference would read while the app is running and its just been saved but on restart it would not show but all the other keys and values would be. Future storeAndOverwrite(SecureStorageContent storedContent) async { await Future.delayed(const Duration( milliseconds: 200)); //do not remove this line seems to be a ios issue where the top line is not stored await storage.write( key: Dummy.biometricPreference, value: storedContent.biometricPreference); await storage.write( key: Dummy.soundPreference, value: storedContent.soundPreference); await storage.write( key: Dummy.vibrationPreference, value: storedContent.vibrationPreference); await storage.write(key: LegacyConstants.email, value: storedContent.email); await storage.write( key: Dummy.password, value: storedContent.password); await storage.write( key: Dummy.accessToken, value: storedContent.accessToken); await getStoredContent(); }

harshitwe360 commented 12 months ago

I have updated with new IOS versions, after that I had got same issue, String type data is not get stored. but its working fine in android, even in IOS debug mode not working in release mode.

Any idea whats going wrong..!

MatthewJones517 commented 11 months ago

I am having the same issue with 9.0.0. Took me forever to track down that this plugin was the problem. Issue only occurs in iOS release builds. Nowhere else.

MatthewJones517 commented 11 months ago

After digging in a bit deeper, I found that this was caused by doing a read immediately after doing a write. We weren't fully awaiting the save, so only part of the value made it in to secure storage before we pulled it out.

I'm not saying that's everyone's problem, but it's something to check for those that stumble on this thread in the future.

Kijacode commented 11 months ago

so @MatthewJones517 , have you solve it ??

cheymos commented 8 months ago

Is the problem still relevant?

aswinranjith-iouring commented 4 months ago

any update on this?

juliansteenbakker commented 4 months ago

Version 9.2.1 fixed a race condition issue with read/write, which could be this issue. It would be great if someone can check if this version still has this issue.

juliansteenbakker commented 1 month ago

I am closing all older issues. If this issue still exists in the latest version, please let me know.