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