flutter_secure_storage icon indicating copy to clipboard operation
flutter_secure_storage copied to clipboard

Write on Mac doesn't overwrite previous value; Delete works fine;

Open tomekit opened this issue 2 years ago • 8 comments

I am experiencing this issue only on macOS. I suspect it's something related to Keychain, but I don't yet have enough experience with the lib internals to trace exactly what's going on.

In some cases when I write new value to a key, the new value doesn't end up in: key. It's like if the write to keychain has failed. However when I delete the: key it gets deleted as expected.

It doesn't make difference if I try to read new value immediately after write or if I wait longer while or even restart app.

final secureStorage = FlutterSecureStorage();
final write = await secureStorage.write(key: "key", value: "newValue");
final value = await secureStorage.read(key: "key"); // Still returns old value !

final delete = await secureStorage.delete(key: "key");
final value = await secureStorage.read(key: "key"); // Key successfully deleted

I use latest: flutter_secure_storage 8.0.0 and Flutter:

[✓] Flutter (Channel stable, 3.10.5, on macOS 13.4 22F66 darwin-arm64, locale en-PL)
    • Flutter version 3.10.5 on channel stable at /Users/tomek/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (12 days ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

This issue doesn't seem to be present on Linux, Windows, iOS, Android and Web.

==

I've also noticed strange inconsistency between key versions depending if I run the "Debug" version of the app from the Android Studio or if I start the "Release" version from the compiled .DMG package.

Once I start release version of the app, I get this prompt signal-2023-06-25-220605_002 and the if I read the key I get the: newValue.

After closing the app and starting the Debug version from the Android Studio: signal-2023-06-25-220605_003 I still get the: oldValue, despite the fact the the: newValue was written from the Debug version.

tomekit avatar Jun 25 '23 19:06 tomekit

I had the same problem

clong1995 avatar Jun 27 '23 01:06 clong1995

Same, we have to delete it before writing the data again.

SebAubin avatar Jun 28 '23 18:06 SebAubin

@SebAubin thanks for the workaround. I have the same issue.

cst1412 avatar Jul 05 '23 07:07 cst1412

That's the big issue I guess. I also face it. Please, fix it or at least make a note in documentation that on Mac key should first be deleted before setting a new value.

Arley011 avatar Sep 07 '23 12:09 Arley011

Experiencing the same issue on Mac too.

jamesdlow avatar Nov 11 '23 04:11 jamesdlow

Same problem here. Setting moption with synchronizable does work either (I gave it a try while not knowing what its intended function is.

I also have to delete before trying to update

macOS Sonoma Flutter (Channel stable, 3.16.4, on macOS 14.1.2 23B92 darwin-arm64, locale en-US)

colinbes avatar Dec 22 '23 22:12 colinbes

Spent a long time banging my head on issues with GQL refreshToken today before realizing that the new token was never written to secureStorage 😓 . Manually deleting the old token first before writing worked.

x-ji avatar May 16 '24 21:05 x-ji

I replied before that I had this issue, but on the current version (9.2.2) I can no longer replicate the issue. There was a recent update (May 16th 2024) that added some code from the iOS implementation, so maybe that helped.

https://github.com/mogol/flutter_secure_storage/commit/76299dd150984ae2194dbb40c7d18741d9b23722

jamesdlow avatar Jun 21 '24 03:06 jamesdlow

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

juliansteenbakker avatar Aug 13 '24 20:08 juliansteenbakker