Skip to content

Commit

Permalink
chore: removed migrateAsfDeviceID from credential_store_state_machine
Browse files Browse the repository at this point in the history
  • Loading branch information
khatruong2009 committed Dec 20, 2023
1 parent 5617a54 commit 2673929
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class LegacyCredentialProviderAndroid implements LegacyCredentialProvider {
final bridge = _stateMachine.expect<auth_cognito.NativeAuthBridge>();
final device = await bridge.fetchLegacyDeviceSecrets(
userPoolConfig?.poolId, userPoolConfig?.appClientId,);

return device?.toLegacyDeviceDetails();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ final class CredentialStoreStateMachine
if (username != null) {
await _migrateDeviceSecrets(username);
}
await _migrateAsfDeviceID();
await _updateVersion(CredentialStoreVersion.v1);
}

Expand Down Expand Up @@ -380,10 +379,7 @@ final class CredentialStoreStateMachine
}

// Migrate Asf Device ID
final legacyDeviceId = await credentialProvider.fetchLegacyDeviceSecrets(
userPoolConfig: authConfig.userPoolConfig,
);
final asfDeviceId = legacyDeviceId?.asfDeviceId;
final asfDeviceId = legacySecrets?.asfDeviceId;
if (asfDeviceId != null) {
await _secureStorage.write(
key: userPoolKeys[CognitoUserPoolKey.asfDeviceId],
Expand All @@ -404,39 +400,6 @@ final class CredentialStoreStateMachine
}
}

// TODO: UPDATE BY COMBINING INTO MIGRATE DEVICE SECRETS

/// Migrates legacy device secrets.
Future<void> _migrateAsfDeviceID() async {
final credentialProvider = get<LegacyCredentialProvider>();
final authConfig = expect<AuthConfiguration>();
final userPoolConfig = authConfig.userPoolConfig;
if (credentialProvider == null || userPoolConfig == null) return;
final userPoolKeys = CognitoUserPoolKeys(userPoolConfig);
try {
final legacyDeviceId = await credentialProvider.fetchLegacyDeviceSecrets(
userPoolConfig: userPoolConfig,
);
final asfDeviceId = legacyDeviceId?.asfDeviceId;
if (asfDeviceId != null) {
await _secureStorage.write(
key: userPoolKeys[CognitoUserPoolKey.asfDeviceId],
value: asfDeviceId,
);
}
} on Object catch (e, s) {
logger.error('Error migrating legacy ASF device ID', e, s);
} finally {
try {
await _secureStorage.delete(
key: userPoolKeys[CognitoUserPoolKey.asfDeviceId],
);
} on Object catch (e, s) {
logger.error('Error clearing legacy ASF device ID', e, s);
}
}
}

/// State machine callback for the [CredentialStoreLoadCredentialStore] event.
Future<void> onLoadCredentialStore(
CredentialStoreLoadCredentialStore event,
Expand Down

0 comments on commit 2673929

Please sign in to comment.