Skip to content

Commit a09c772

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

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
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 null;
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 & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ 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();
3940
final cognitoUserKeys =
40-
LegacyCognitoUserKeys(authOutputs.userPoolClientId!);
41+
LegacyCognitoUserKeys(userPoolClientId);
4142
final currentUserId = await userPoolStorage.read(
4243
key: cognitoUserKeys[LegacyCognitoKey.currentUser],
4344
);
4445
if (currentUserId != null) {
4546
final userPoolKeys = LegacyCognitoUserPoolKeys(
4647
currentUserId,
47-
authOutputs.userPoolClientId!,
48+
userPoolClientId,
4849
);
4950
final accessToken = await userPoolStorage.read(
5051
key: userPoolKeys[LegacyCognitoUserPoolKey.accessToken],
@@ -72,9 +73,10 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
7273

7374
String? identityId;
7475
AWSCredentials? awsCredentials;
75-
if (authOutputs.identityPoolId != null) {
76+
final identityPoolId = authOutputs.identityPoolId;
77+
if (identityPoolId != null) {
7678
final identityPoolStorage = await _getIdentityPoolStorage(
77-
authOutputs.identityPoolId!,
79+
identityPoolId,
7880
);
7981
const identityPoolKeys = LegacyCognitoIdentityPoolKeys();
8082
identityId = await identityPoolStorage.read(
@@ -125,17 +127,18 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
125127
Future<void> deleteLegacyCredentials(
126128
AuthOutputs authOutputs,
127129
) async {
128-
if (authOutputs.userPoolClientId != null) {
130+
final userPoolClientId = authOutputs.userPoolClientId;
131+
if (userPoolClientId != null) {
129132
final userPoolStorage = await _getUserPoolStorage();
130133
final cognitoUserKeys =
131-
LegacyCognitoUserKeys(authOutputs.userPoolClientId!);
134+
LegacyCognitoUserKeys(userPoolClientId);
132135
final currentUser = await userPoolStorage.read(
133136
key: cognitoUserKeys[LegacyCognitoKey.currentUser],
134137
);
135138
if (currentUser != null) {
136139
final userPoolKeys = LegacyCognitoUserPoolKeys(
137140
currentUser,
138-
authOutputs.userPoolClientId!,
141+
userPoolClientId,
139142
);
140143
await userPoolStorage.deleteMany([
141144
userPoolKeys[LegacyCognitoUserPoolKey.accessToken],
@@ -165,17 +168,19 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
165168
String username,
166169
AuthOutputs authOutputs,
167170
) async {
168-
if (authOutputs.userPoolClientId == null) return null;
171+
final userPoolClientId = authOutputs.userPoolClientId;
172+
if (userPoolClientId == null) return null;
169173
final userPoolStorage = await _getUserPoolStorage();
170174
final cognitoUserKeys =
171-
LegacyCognitoUserKeys(authOutputs.userPoolClientId!);
175+
LegacyCognitoUserKeys(userPoolClientId);
172176
final currentUserId = await userPoolStorage.read(
173177
key: cognitoUserKeys[LegacyCognitoKey.currentUser],
174178
);
175-
if (currentUserId == null || authOutputs.userPoolId == null) return null;
179+
final userPoolId = authOutputs.userPoolId;
180+
if (currentUserId == null || userPoolId == null) return null;
176181
final keys = LegacyDeviceSecretKeys(
177182
currentUserId,
178-
authOutputs.userPoolId!,
183+
userPoolId,
179184
);
180185
final deviceKey = await userPoolStorage.read(
181186
key: keys[LegacyDeviceSecretKey.id],
@@ -187,7 +192,7 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
187192
key: keys[LegacyDeviceSecretKey.group],
188193
);
189194

190-
final asfKeys = LegacyAsfDeviceKeys(currentUserId, authOutputs.userPoolId!);
195+
final asfKeys = LegacyAsfDeviceKeys(currentUserId, userPoolId);
191196
final asfDeviceId = await userPoolStorage.read(
192197
key: asfKeys[LegacyAsfDeviceKey.id],
193198
);
@@ -205,16 +210,18 @@ class LegacyCredentialProviderIOS implements LegacyCredentialProvider {
205210
String username,
206211
AuthOutputs authOutputs,
207212
) async {
208-
if (authOutputs.userPoolClientId == null) return;
213+
final userPoolClientId = authOutputs.userPoolClientId;
214+
if (userPoolClientId == null) return;
209215
final userPoolStorage = await _getUserPoolStorage();
210216
final cognitoUserKeys =
211-
LegacyCognitoUserKeys(authOutputs.userPoolClientId!);
217+
LegacyCognitoUserKeys(userPoolClientId);
212218
final currentUserId = await userPoolStorage.read(
213219
key: cognitoUserKeys[LegacyCognitoKey.currentUser],
214220
);
215-
if (currentUserId == null || authOutputs.userPoolId == null) return;
216-
final keys = LegacyDeviceSecretKeys(currentUserId, authOutputs.userPoolId!);
217-
final asfKeys = LegacyAsfDeviceKeys(currentUserId, authOutputs.userPoolId!);
221+
final userPoolId = authOutputs.userPoolId;
222+
if (currentUserId == null || userPoolId == null) return;
223+
final keys = LegacyDeviceSecretKeys(currentUserId, userPoolId);
224+
final asfKeys = LegacyAsfDeviceKeys(currentUserId, userPoolId);
218225
await userPoolStorage.deleteMany([
219226
keys[LegacyDeviceSecretKey.id],
220227
keys[LegacyDeviceSecretKey.secret],

0 commit comments

Comments
 (0)