Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(auth): hosted ui state machine to not use AmplifyConfig types #5254

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading