fix: credentials not persisting on some devices
This commit is contained in:
@@ -29,7 +29,20 @@ final sharedPreferencesProvider = Provider<SharedPreferences>((ref) {
|
||||
});
|
||||
|
||||
final secureStorageProvider = Provider<FlutterSecureStorage>((ref) {
|
||||
return const FlutterSecureStorage();
|
||||
// Single, shared instance with explicit platform options
|
||||
return const FlutterSecureStorage(
|
||||
aOptions: AndroidOptions(
|
||||
encryptedSharedPreferences: true,
|
||||
sharedPreferencesName: 'conduit_secure_prefs',
|
||||
preferencesKeyPrefix: 'conduit_',
|
||||
// Avoid auto-wipe on transient errors; we handle errors in code
|
||||
resetOnError: false,
|
||||
),
|
||||
iOptions: IOSOptions(
|
||||
accountName: 'conduit_secure_storage',
|
||||
synchronizable: false,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
final storageServiceProvider = Provider<StorageService>((ref) {
|
||||
|
||||
@@ -16,7 +16,7 @@ class OptimizedStorageService {
|
||||
required FlutterSecureStorage secureStorage,
|
||||
required SharedPreferences prefs,
|
||||
}) : _prefs = prefs,
|
||||
_secureCredentialStorage = SecureCredentialStorage();
|
||||
_secureCredentialStorage = SecureCredentialStorage(instance: secureStorage);
|
||||
|
||||
// Optimized key names with versioning
|
||||
static const String _authTokenKey = 'auth_token_v3';
|
||||
|
||||
@@ -8,8 +8,8 @@ import '../utils/debug_logger.dart';
|
||||
class SecureCredentialStorage {
|
||||
late final FlutterSecureStorage _secureStorage;
|
||||
|
||||
SecureCredentialStorage() {
|
||||
_secureStorage = FlutterSecureStorage(
|
||||
SecureCredentialStorage({FlutterSecureStorage? instance}) {
|
||||
_secureStorage = instance ?? FlutterSecureStorage(
|
||||
aOptions: _getAndroidOptions(),
|
||||
iOptions: _getIOSOptions(),
|
||||
);
|
||||
@@ -25,10 +25,8 @@ class SecureCredentialStorage {
|
||||
encryptedSharedPreferences: true,
|
||||
sharedPreferencesName: 'conduit_secure_prefs',
|
||||
preferencesKeyPrefix: 'conduit_',
|
||||
resetOnError: true,
|
||||
// Use more compatible encryption algorithms
|
||||
keyCipherAlgorithm: KeyCipherAlgorithm.RSA_ECB_PKCS1Padding,
|
||||
storageCipherAlgorithm: StorageCipherAlgorithm.AES_CBC_PKCS7Padding,
|
||||
// Avoid auto-wipe on transient errors; handle gracefully in code
|
||||
resetOnError: false,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class StorageService {
|
||||
required SharedPreferences prefs,
|
||||
}) : _secureStorage = secureStorage,
|
||||
_prefs = prefs,
|
||||
_secureCredentialStorage = SecureCredentialStorage();
|
||||
_secureCredentialStorage = SecureCredentialStorage(instance: secureStorage);
|
||||
|
||||
// Secure storage keys
|
||||
static const String _authTokenKey = 'auth_token';
|
||||
|
||||
@@ -29,7 +29,18 @@ void main() async {
|
||||
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
|
||||
final sharedPrefs = await SharedPreferences.getInstance();
|
||||
const secureStorage = FlutterSecureStorage();
|
||||
const secureStorage = FlutterSecureStorage(
|
||||
aOptions: AndroidOptions(
|
||||
encryptedSharedPreferences: true,
|
||||
sharedPreferencesName: 'conduit_secure_prefs',
|
||||
preferencesKeyPrefix: 'conduit_',
|
||||
resetOnError: false,
|
||||
),
|
||||
iOptions: IOSOptions(
|
||||
accountName: 'conduit_secure_storage',
|
||||
synchronizable: false,
|
||||
),
|
||||
);
|
||||
|
||||
runApp(
|
||||
ProviderScope(
|
||||
|
||||
Reference in New Issue
Block a user