From 3ca82b385a272a1169c3a46a483ab228d0d6982c Mon Sep 17 00:00:00 2001 From: Nika Hassani Date: Wed, 7 Aug 2024 17:18:42 -0400 Subject: [PATCH] chore(auth): hostedui state machine to not use AmplifyConfig types --- .../machines/hosted_ui_state_machine.dart | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/hosted_ui_state_machine.dart b/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/hosted_ui_state_machine.dart index 8c3806aba7..59c109122f 100644 --- a/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/hosted_ui_state_machine.dart +++ b/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/hosted_ui_state_machine.dart @@ -11,6 +11,8 @@ import 'package:amplify_auth_cognito_dart/src/model/auth_user_ext.dart'; import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart'; import 'package:amplify_auth_cognito_dart/src/state/state.dart'; import 'package:amplify_core/amplify_core.dart'; +// ignore: implementation_imports +import 'package:amplify_core/src/config/amplify_outputs/auth/auth_outputs.dart'; import 'package:amplify_secure_storage_dart/amplify_secure_storage_dart.dart'; /// {@template amplify_auth_cognito.hosted_ui_state_machine} @@ -31,16 +33,20 @@ final class HostedUiStateMachine @override String get runtimeTypeName => 'HostedUiStateMachine'; - CognitoOAuthConfig get _config => expect(); - HostedUiKeys get _keys => HostedUiKeys(_config.appClientId); + AuthOutputs get _authOutputs { + final authOutputs = get(); + if (authOutputs?.oauth == null || authOutputs?.userPoolClientId == null) { + throw const InvalidAccountTypeException.noUserPool(); + } + return authOutputs!; + } + + HostedUiKeys get _keys => HostedUiKeys(_authOutputs.userPoolClientId!); SecureStorageInterface get _secureStorage => getOrCreate(); /// The platform-specific behavior. HostedUiPlatform get _platform => getOrCreate(); - /// The configured identity pool. - CognitoIdentityCredentialsProvider? get _identityPoolConfig => get(); - @override Future resolve(HostedUiEvent event) async { switch (event) { @@ -192,9 +198,9 @@ final class HostedUiStateMachine // Clear anonymous credentials, if there were any, and fetch authenticated // credentials. - if (_identityPoolConfig != null) { + if (_authOutputs.identityPoolId != null) { await manager.clearCredentials( - CognitoIdentityPoolKeys(_identityPoolConfig!.poolId), + CognitoIdentityPoolKeys(_authOutputs.identityPoolId!), ); await manager.loadSession();