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

fix(Authenticator): Handling expired sessions #87

Merged
merged 3 commits into from
Aug 13, 2024

Conversation

sebaland
Copy link
Contributor

Issue #, if available:

Description of changes:

When a user session cannot be refreshed, Amplify.Auth.fetchAuthSession() will still return isSignedIn: true, but attempting to perform any operation that requires authentication will subsequently fail and ask the user to log in again.

This is a known thing within Amplify, but can be handled by the Authenticator by signing out the user if we detect their session has expired when the component is launched.

This PR proposes validating that a session has valid identity ID and/or Cognito tokens, depending on what type of configuration the user is using:

  • If they only have CognitoIdentity, only check for a valid `session.getIdentityId()
  • If they only have CognitoUserPool, only check for valid session.getCognitoTokens().
  • If they have both, check for both session.getIdentityId() and session.getCognitoTokens().

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

@sebaland sebaland requested review from a team as code owners August 12, 2024 14:46
@sebaland sebaland requested a review from phantumcode August 12, 2024 14:48
phantumcode
phantumcode previously approved these changes Aug 12, 2024
Copy link

codecov bot commented Aug 12, 2024

Codecov Report

Attention: Patch coverage is 11.42857% with 31 lines in your changes missing coverage. Please review.

Project coverage is 41.69%. Comparing base (2518b16) to head (1f05357).
Report is 1 commits behind head on main.

Files Patch % Lines
...rces/Authenticator/Models/AuthenticatorState.swift 0.00% 20 Missing ⚠️
...enticator/Configuration/AmplifyConfiguration.swift 26.66% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
- Coverage   42.20%   41.69%   -0.51%     
==========================================
  Files          41       41              
  Lines        1872     1902      +30     
==========================================
+ Hits          790      793       +3     
- Misses       1082     1109      +27     
Flag Coverage Δ
Authenticator 41.69% <11.42%> (-0.51%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sebaland sebaland merged commit 0fcd480 into main Aug 13, 2024
4 checks passed
@sebaland sebaland deleted the ruisebas/expired_sessions branch August 13, 2024 18:57
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.

2 participants