Skip to content
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

[Android][iOS] Unable to read any data #837

Open
tlvdvlpmnt opened this issue Dec 11, 2024 · 5 comments
Open

[Android][iOS] Unable to read any data #837

tlvdvlpmnt opened this issue Dec 11, 2024 · 5 comments

Comments

@tlvdvlpmnt
Copy link

We are using version ^8.0.0 (8.1.0 in builds). Recently started getting reports from users that they can't read any data from iOS keychain (iOS18.1.1). After some time noticed that the problem with reading data is also present on android. This is not reproducible for all users. Our team cannot reproduce this problem.

Maybe someone has encountered the problem of reading data that was previously read successfully?

IOSOptions _getIOSOptions() => IOSOptions(accountName: storageIdentifier);

  AndroidOptions _getAndroidOptions() =>
      AndroidOptions(encryptedSharedPreferences: true, sharedPreferencesName: storageIdentifier);

  @override
  Future<String?> getValue(String key) => _storage.read(
    key: key,
    iOptions: _getIOSOptions(),
    aOptions: _getAndroidOptions(),
  );
@AsherJi
Copy link

AsherJi commented Dec 13, 2024

We also encountered a similar issue, especially when the iOS app has just launched, where data previously stored in the keychain may be read as null. This problem occurs with a certain probability and does not happen every time.This issue suddenly appeared after updating to iOS 18.

@PWrzesinski
Copy link

PWrzesinski commented Dec 14, 2024

This is currently a complete blocker. For me this issue happened on Android previously, but I've upgraded to the latest Flutter (3.27) today and FlutterSecureStorage started to return null for read on both Android and iOS (the Flutter upgrade might or might not be related, I've also had to upgrade many dependencies, cocoa pods, clean the project, etc.). I'm currently on flutter_secure_storage: ^9.2.2, so the latest version, but before today I used 9.0.0.

Update: turns out you need to specify the same iOS options for read as for write. This requirement seems to be new. This fixed the problem for me on iOS, as I previously saved some data with default options and some with first_unlock, while reading everything with default options. For details, see: #762

Update 2: on Android, in case you're using more than one FlutterSecureStorage instance, you need to specify the same options for all instances. For me this solves all issues. Would be good to have better documentation to prevent such issues in the future.

@y-hakutaku
Copy link

y-hakutaku commented Dec 17, 2024

@tlvdvlpmnt
I am encountering the same issue on iOS only.
Specifically, when the app version changes, the previous data cannot be loaded.
This occurs with an archive build.
At first, I thought it was a difference between release and debug builds, but the issue does not occur when running a release build locally.

@benja8151
Copy link

Update 2: on Android, in case you're using more than one FlutterSecureStorage instance, you need to specify the same options for all instances. For me this solves all issues. Would be good to have better documentation to prevent such issues in the future.

For me, it is working while I am using multiple FlutterSecureStorage instances with different options:

First:
aOptions: AndroidOptions(
    encryptedSharedPreferences: true,
    preferencesKeyPrefix: 'session_storage_',
    sharedPreferencesName: 'app_session_storage_',
)

Second: 
aOptions: AndroidOptions(
    encryptedSharedPreferences: true,
    preferencesKeyPrefix: 'secure_storage_',
    sharedPreferencesName: 'app_secure_storage_',
)

However, it was not working before I added preferencesKeyPrefix and sharedPreferencesName to the second options.

@PWrzesinski
Copy link

Update 2: on Android, in case you're using more than one FlutterSecureStorage instance, you need to specify the same options for all instances. For me this solves all issues. Would be good to have better documentation to prevent such issues in the future.

For me, it is working while I am using multiple FlutterSecureStorage instances with different options:

First:
aOptions: AndroidOptions(
    encryptedSharedPreferences: true,
    preferencesKeyPrefix: 'session_storage_',
    sharedPreferencesName: 'app_session_storage_',
)

Second: 
aOptions: AndroidOptions(
    encryptedSharedPreferences: true,
    preferencesKeyPrefix: 'secure_storage_',
    sharedPreferencesName: 'app_secure_storage_',
)

However, it was not working before I added preferencesKeyPrefix and sharedPreferencesName to the second options.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants