Skip to content

Commit abcc1cd

Browse files
NikaHsntyllark
authored andcommitted
chore(auth): hosted ui state machine to not use AmplifyConfig types (aws-amplify#5254)
1 parent 0f0fe59 commit abcc1cd

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/hosted_ui_state_machine.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import 'package:amplify_auth_cognito_dart/src/model/auth_user_ext.dart';
1111
import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart';
1212
import 'package:amplify_auth_cognito_dart/src/state/state.dart';
1313
import 'package:amplify_core/amplify_core.dart';
14+
// ignore: implementation_imports
15+
import 'package:amplify_core/src/config/amplify_outputs/auth/auth_outputs.dart';
1416
import 'package:amplify_secure_storage_dart/amplify_secure_storage_dart.dart';
1517

1618
/// {@template amplify_auth_cognito.hosted_ui_state_machine}
@@ -31,16 +33,20 @@ final class HostedUiStateMachine
3133
@override
3234
String get runtimeTypeName => 'HostedUiStateMachine';
3335

34-
CognitoOAuthConfig get _config => expect();
35-
HostedUiKeys get _keys => HostedUiKeys(_config.appClientId);
36+
AuthOutputs get _authOutputs {
37+
final authOutputs = get<AuthOutputs>();
38+
if (authOutputs?.oauth == null || authOutputs?.userPoolClientId == null) {
39+
throw const InvalidAccountTypeException.noUserPool();
40+
}
41+
return authOutputs!;
42+
}
43+
44+
HostedUiKeys get _keys => HostedUiKeys(_authOutputs.userPoolClientId!);
3645
SecureStorageInterface get _secureStorage => getOrCreate();
3746

3847
/// The platform-specific behavior.
3948
HostedUiPlatform get _platform => getOrCreate();
4049

41-
/// The configured identity pool.
42-
CognitoIdentityCredentialsProvider? get _identityPoolConfig => get();
43-
4450
@override
4551
Future<void> resolve(HostedUiEvent event) async {
4652
switch (event) {
@@ -192,9 +198,9 @@ final class HostedUiStateMachine
192198

193199
// Clear anonymous credentials, if there were any, and fetch authenticated
194200
// credentials.
195-
if (_identityPoolConfig != null) {
201+
if (_authOutputs.identityPoolId != null) {
196202
await manager.clearCredentials(
197-
CognitoIdentityPoolKeys(_identityPoolConfig!.poolId),
203+
CognitoIdentityPoolKeys(_authOutputs.identityPoolId!),
198204
);
199205

200206
await manager.loadSession();

0 commit comments

Comments
 (0)