Skip to content

fix(auth): SessionExpired Auth Hub event #2609

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

Merged

Conversation

Jordan-Nelson
Copy link
Member

Issue #, if available:

Description of changes:

Fixes a regression introduced by #2585. When refreshing user pool tokens fail due to an expired refresh token, a hub event for Session Expired should be emitted.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Jordan-Nelson Jordan-Nelson requested a review from a team as a code owner January 30, 2023 16:40
hubEvent = AuthHubEvent.sessionExpired();
if (state is FetchAuthSessionSuccess) {
final exception = state.session.userPoolTokensResult.exception;
// TODO(Jordan-Nelson): Update list of exceptions once FetchAuthSession
Copy link
Member Author

@Jordan-Nelson Jordan-Nelson Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, an AuthNotAuthorizedException is thrown for an expired session, but it should be SessionExpiredException. This has always been the case in next and I have a task to update this.

UnauthorizedException was in the list previously, so I left it for now. I'll look into what scenarios what is thrown in to see if this needs to be included when I take care of the task mentioned above.


test('should add a sessionExpired event to Auth Hub', () async {
final authStream = Amplify.Hub.availableStreams[HubChannel.Auth];
plugin.fetchAuthSession().ignore();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might fail on DDC - it doesn't like .ignore in tests for some reason (maybe due to #50619 in the Dart repo). Alternative is the same but more verbose:

unawaited(
  plugin.fetchAuthSession().then((_) {}).onError((_, __) {}),
);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They seem to be passing (at least on firefox, looks like they are not running on Chrome) so I will leave for now. If it causes an issue we can change it.

@Jordan-Nelson Jordan-Nelson merged commit f49134a into aws-amplify:next Jan 30, 2023
@Jordan-Nelson Jordan-Nelson deleted the fix/session-expired-hub-event branch January 30, 2023 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants