storeCredentials method
Store credentials with biometric protection
Implementation
Future<void> storeCredentials(
Map<String, dynamic> credentials, {
bool requireBiometrics = false,
String? customKey,
}) async {
try {
OnairosDebugHelper.log('🔐 Storing credentials with enhanced security');
// Check if biometric authentication is required and available
if (requireBiometrics && await _isBiometricsAvailable()) {
final authenticated = await _authenticateWithBiometrics('Store credentials securely');
if (!authenticated) {
throw Exception('Biometric authentication required to store credentials');
}
}
// Store credentials as JSON
final credentialsJson = jsonEncode(credentials);
final key = customKey ?? 'onairos_credentials_enhanced';
await _secureStorage.write(key: key, value: credentialsJson);
// Store timestamp for tracking
await _secureStorage.write(
key: '${key}_timestamp',
value: DateTime.now().millisecondsSinceEpoch.toString(),
);
OnairosDebugHelper.log('✅ Credentials stored successfully');
} catch (e) {
OnairosDebugHelper.log('❌ Error storing credentials: $e');
rethrow;
}
}