Skip to content

Commit

Permalink
chore(auth): hosted ui state machine to not use AmplifyConfig types (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
NikaHsn authored Aug 12, 2024
1 parent 11ba134 commit 9c12c93
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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<AuthOutputs>();
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<void> resolve(HostedUiEvent event) async {
switch (event) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9c12c93

Please sign in to comment.