From 2aeded7f48862c1f56894428da371b4d198f2fb8 Mon Sep 17 00:00:00 2001 From: Jordan Nelson Date: Thu, 31 Aug 2023 14:52:35 -0400 Subject: [PATCH] fix(auth): use loadCredentials to check login state --- .../lib/src/state/machines/sign_in_state_machine.dart | 4 ++-- .../test/state/sign_in_state_machine_test.dart | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/sign_in_state_machine.dart b/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/sign_in_state_machine.dart index 6ca772bf4d..714b178016 100644 --- a/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/sign_in_state_machine.dart +++ b/packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/sign_in_state_machine.dart @@ -770,8 +770,8 @@ final class SignInStateMachine Future _assertSignedOut() async { bool isSignedIn; try { - await manager.getUserPoolTokens(); - isSignedIn = true; + final credentials = await manager.loadCredentials(); + isSignedIn = credentials.userPoolTokens != null; } on Exception { isSignedIn = false; } diff --git a/packages/auth/amplify_auth_cognito_test/test/state/sign_in_state_machine_test.dart b/packages/auth/amplify_auth_cognito_test/test/state/sign_in_state_machine_test.dart index 6ac4bfccb5..24925b7b26 100644 --- a/packages/auth/amplify_auth_cognito_test/test/state/sign_in_state_machine_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/state/sign_in_state_machine_test.dart @@ -136,6 +136,15 @@ void main() { ).ignore(); final signInStateMachine = stateMachine.expect(SignInStateMachine.type); + + final fetchAuthSessionStateMachine = stateMachine.getOrCreate( + FetchAuthSessionStateMachine.type, + ); + + fetchAuthSessionStateMachine.stream.listen( + (_) => throw StateError('.signIn() should not fetch auth session.'), + ); + expect( signInStateMachine.stream, emitsInOrder([