Skip to content

Commit 1ea7f5f

Browse files
author
Nika Hassani
committed
address comments to not use null assertion
1 parent 90a7f7e commit 1ea7f5f

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

packages/auth/amplify_auth_cognito/lib/src/credentials/legacy_credential_provider_android.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ class LegacyCredentialProviderAndroid implements LegacyCredentialProvider {
4747
String username,
4848
AuthOutputs authOutputs,
4949
) async {
50-
if (authOutputs.userPoolId == null) return null;
50+
final userPoolId = authOutputs.userPoolId;
51+
if (userPoolId == null) return null;
5152
final bridge = _stateMachine.expect<auth_cognito.NativeAuthBridge>();
5253
final device = await bridge.fetchLegacyDeviceSecrets(
5354
username,
54-
authOutputs.userPoolId!,
55+
userPoolId,
5556
);
5657
return device?.toLegacyDeviceDetails();
5758
}
@@ -61,12 +62,12 @@ class LegacyCredentialProviderAndroid implements LegacyCredentialProvider {
6162
String username,
6263
AuthOutputs authOutputs,
6364
) async {
64-
if (authOutputs.userPoolId != null) {
65-
final bridge = _stateMachine.expect<auth_cognito.NativeAuthBridge>();
66-
return bridge.deleteLegacyDeviceSecrets(
67-
username,
68-
authOutputs.userPoolId!,
69-
);
70-
}
65+
final userPoolId = authOutputs.userPoolId;
66+
if (userPoolId == null) return;
67+
final bridge = _stateMachine.expect<auth_cognito.NativeAuthBridge>();
68+
return bridge.deleteLegacyDeviceSecrets(
69+
username,
70+
userPoolId,
71+
);
7172
}
7273
}

packages/auth/amplify_auth_cognito/lib/src/credentials/legacy_credential_provider_ios.dart

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
3434
AuthOutputs authOutputs,
3535
) async {
3636
CognitoUserPoolTokens? userPoolTokens;
37-
if (authOutputs.userPoolClientId != null) {
37+
final userPoolClientId = authOutputs.userPoolClientId;
38+
if (userPoolClientId != null) {
3839
final userPoolStorage = await _getUserPoolStorage();
39-
final cognitoUserKeys =
40-
LegacyCognitoUserKeys(authOutputs.userPoolClientId!);
40+
final cognitoUserKeys = LegacyCognitoUserKeys(userPoolClientId);
4141
final currentUserId = await userPoolStorage.read(
4242
key: cognitoUserKeys[LegacyCognitoKey.currentUser],
4343
);
4444
if (currentUserId != null) {
4545
final userPoolKeys = LegacyCognitoUserPoolKeys(
4646
currentUserId,
47-
authOutputs.userPoolClientId!,
47+
userPoolClientId,
4848
);
4949
final accessToken = await userPoolStorage.read(
5050
key: userPoolKeys[LegacyCognitoUserPoolKey.accessToken],
@@ -72,9 +72,10 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
7272

7373
String? identityId;
7474
AWSCredentials? awsCredentials;
75-
if (authOutputs.identityPoolId != null) {
75+
final identityPoolId = authOutputs.identityPoolId;
76+
if (identityPoolId != null) {
7677
final identityPoolStorage = await _getIdentityPoolStorage(
77-
authOutputs.identityPoolId!,
78+
identityPoolId,
7879
);
7980
const identityPoolKeys = LegacyCognitoIdentityPoolKeys();
8081
identityId = await identityPoolStorage.read(
@@ -125,17 +126,17 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
125126
Future<void> deleteLegacyCredentials(
126127
AuthOutputs authOutputs,
127128
) async {
128-
if (authOutputs.userPoolClientId != null) {
129+
final userPoolClientId = authOutputs.userPoolClientId;
130+
if (userPoolClientId != null) {
129131
final userPoolStorage = await _getUserPoolStorage();
130-
final cognitoUserKeys =
131-
LegacyCognitoUserKeys(authOutputs.userPoolClientId!);
132+
final cognitoUserKeys = LegacyCognitoUserKeys(userPoolClientId);
132133
final currentUser = await userPoolStorage.read(
133134
key: cognitoUserKeys[LegacyCognitoKey.currentUser],
134135
);
135136
if (currentUser != null) {
136137
final userPoolKeys = LegacyCognitoUserPoolKeys(
137138
currentUser,
138-
authOutputs.userPoolClientId!,
139+
userPoolClientId,
139140
);
140141
await userPoolStorage.deleteMany([
141142
userPoolKeys[LegacyCognitoUserPoolKey.accessToken],
@@ -165,17 +166,18 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
165166
String username,
166167
AuthOutputs authOutputs,
167168
) async {
168-
if (authOutputs.userPoolClientId == null) return null;
169+
final userPoolClientId = authOutputs.userPoolClientId;
170+
if (userPoolClientId == null) return null;
169171
final userPoolStorage = await _getUserPoolStorage();
170-
final cognitoUserKeys =
171-
LegacyCognitoUserKeys(authOutputs.userPoolClientId!);
172+
final cognitoUserKeys = LegacyCognitoUserKeys(userPoolClientId);
172173
final currentUserId = await userPoolStorage.read(
173174
key: cognitoUserKeys[LegacyCognitoKey.currentUser],
174175
);
175-
if (currentUserId == null || authOutputs.userPoolId == null) return null;
176+
final userPoolId = authOutputs.userPoolId;
177+
if (currentUserId == null || userPoolId == null) return null;
176178
final keys = LegacyDeviceSecretKeys(
177179
currentUserId,
178-
authOutputs.userPoolId!,
180+
userPoolId,
179181
);
180182
final deviceKey = await userPoolStorage.read(
181183
key: keys[LegacyDeviceSecretKey.id],
@@ -187,7 +189,7 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
187189
key: keys[LegacyDeviceSecretKey.group],
188190
);
189191

190-
final asfKeys = LegacyAsfDeviceKeys(currentUserId, authOutputs.userPoolId!);
192+
final asfKeys = LegacyAsfDeviceKeys(currentUserId, userPoolId);
191193
final asfDeviceId = await userPoolStorage.read(
192194
key: asfKeys[LegacyAsfDeviceKey.id],
193195
);
@@ -205,16 +207,17 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
205207
String username,
206208
AuthOutputs authOutputs,
207209
) async {
208-
if (authOutputs.userPoolClientId == null) return;
210+
final userPoolClientId = authOutputs.userPoolClientId;
211+
if (userPoolClientId == null) return;
209212
final userPoolStorage = await _getUserPoolStorage();
210-
final cognitoUserKeys =
211-
LegacyCognitoUserKeys(authOutputs.userPoolClientId!);
213+
final cognitoUserKeys = LegacyCognitoUserKeys(userPoolClientId);
212214
final currentUserId = await userPoolStorage.read(
213215
key: cognitoUserKeys[LegacyCognitoKey.currentUser],
214216
);
215-
if (currentUserId == null || authOutputs.userPoolId == null) return;
216-
final keys = LegacyDeviceSecretKeys(currentUserId, authOutputs.userPoolId!);
217-
final asfKeys = LegacyAsfDeviceKeys(currentUserId, authOutputs.userPoolId!);
217+
final userPoolId = authOutputs.userPoolId;
218+
if (currentUserId == null || userPoolId == null) return;
219+
final keys = LegacyDeviceSecretKeys(currentUserId, userPoolId);
220+
final asfKeys = LegacyAsfDeviceKeys(currentUserId, userPoolId);
218221
await userPoolStorage.deleteMany([
219222
keys[LegacyDeviceSecretKey.id],
220223
keys[LegacyDeviceSecretKey.secret],

0 commit comments

Comments
 (0)