Skip to content

Inconsistent behavior when session expires (refresh token dead) #3943

@dcristolovean

Description

@dcristolovean

Describe the bug

I'm transitioning from AWSMobileClient to Amplify and it's a huge endeavor. I'm a bit stuck with handling session expiration cases and it might be a bug (or intended behavior, but then see the questions).
My app is configured to use auth user AND non-auth users.

So, let's assume in my Amplify.Hub.listen (...) I receive the sessionExpired event.
This leaves me in a totally inconsistent state, where, I would like to revert to a non-auth user and continue using the app. Or display something, doesn't matter.

But when I get the sessionExpired event, nothing works anymore: fetchAuthSession is dead, getIdentityId is dead, API calls are dead.
And the reason for that is that the fetchAuthSession returns isSignedIn = true and still has a user stalled somewhere.

The only way I could transition back to a non auth user is to call Amplify.Auth.signOut() and actually get rid of my bad user. After that, everything works again, I am a non-auth user.

This approach has one big problem: the user plays in the app and suddenly he gets the system dialog to sign in. We all know the issue with that text in the system dialog. It's really bad to just show this dialog out of the blue. And they might press CANCEL.

So... how can I get rid of the logged in user with the expired session ? Silently, not showing anything to the user.

PS: (Rant) The documentation is, again, completely useless, doesn't explain anything, doesn't give any actual real world examples. I'm using AWS for 10 years now and this was always the weak link. I expected Amplify to finally fix this issue, but unfortunately the documentation is just as useless as before.

PS2: Interestingly enough, on Android, according to my colleague, when he gets a sessionExpired in the Hub, calling fetchAuthSession magically fixes everything, session doesn't show signed in anymore and no user left to sign out and he's a non-auth user with a new identityId.

Steps To Reproduce

Kinda hard to provide some steps, it's a more generic theoretical question

Expected behavior

  1. Either clean up the user when sessionExpires automatically and make sure we have an non-auth user working.
  2. Provide another signOut() way without web. I use SSO and I need the cookies. This user is actually local, the session is dead anyway, so not really sure what a webpage is supposed to do with it and why it's needed to log out in this case.

Amplify Framework Version

2.45.2

Amplify Categories

Auth

Dependency manager

Swift PM

Platforms

iOS

Metadata

Metadata

Assignees

Labels

authIssues related to the Auth categoryquestionGeneral question

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions