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

MCR-3849 Fix session timeout #2719

Merged
merged 30 commits into from
Sep 16, 2024
Merged

MCR-3849 Fix session timeout #2719

merged 30 commits into from
Sep 16, 2024

Conversation

haworku
Copy link
Contributor

@haworku haworku commented Sep 3, 2024

Summary

Address issues with session timeout and re-implement with IdleTimer .

Issues addressed include:

  • logout and continue work across tabs
  • if one tab has session timeout modal open then user opens another tab and then lets computer go to sleep, both tabs will be logged out of MC-Review after time elapses with no action
  • if user tries to add a document with file upload but it fails due to IDM having been logged out in the background for whatever reason, MC-Review will also force logout at this point and display session timeout message so the user knows what happened

Still in progress

  • write up acceptance jams steps
  • finish adding AuthenticatedRouteWrapper tests for idle timer behaviors

Related issues

https://jiraent.cms.gov/browse/MCR-3849

Screenshots

Screenshot 2024-09-04 at 4 13 22 PM

Test cases covered

Session Timeout acceptance jam document forthcoming

QA guidance

Please re-test the steps from this comment in Jira.

And also pick a couple of these acceptance jam cases to retest. Keep in mind the timeout for toph in review apps is set to 2min to make things go faster so you won't have to wait as long to verify things.

@haworku haworku changed the title Mcr 3849 sessiontimeout MCR-3849 Fix session timeout Sep 3, 2024
- inherit from base Modal
- create SessionTimeoutModal as own component
- simplify styles
- removing V2 naming from UnlockResubmitModal
- add  to package.json
- remove session timeout custom timekeeping, props from AuthContext
- add IdleTimer to AuthenticatedRouteWrapper
- start to add tests
@haworku haworku marked this pull request as ready for review September 4, 2024 21:14
@pearl-truss
Copy link
Contributor

@haworku for "logout and continue work across tabs", is this the desired behavior? When I logged out of one tab I was still able to do work in another tab

@haworku
Copy link
Contributor Author

haworku commented Sep 5, 2024

@pearl-truss No, that's the buggy behavior that we want to test for and hopefully we don't see it.

Can you send me the replication steps you used and which user in the review app you were using (toph currently has shorter session duration)

@pearl-truss
Copy link
Contributor

@pearl-truss No, that's the buggy behavior that we want to test for and hopefully we don't see it.

Can you send me the replication steps you used and which user in the review app you were using (toph currently has shorter session duration)

I was using aang.

  1. I signed into 2 tabs
  2. I signed out of one tab (it wasn't a session time out, I explicitly signed out)
  3. I used the remaining open tab to view a draft submission

@haworku
Copy link
Contributor Author

haworku commented Sep 6, 2024

@pearl-truss TY for finding this! I added to acceptance testing script under a new section called basic login and logout.

FYI from discussion in standup today, looks like this one is an existing bug not a new regression, and not in scope for this ticket. The bug shouldn't block this PR going through. However, I will still look into solving it also on this branch in case I can fix now, will ping you if I do so.

If you see any other issues, please raise them – this manual testing is very helpful.

Copy link
Contributor

@macrael macrael left a comment

Choose a reason for hiding this comment

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

Love getting to replace custom code with a solid library. I have some questions about us throwing errors we get from Amplify but otherwise this looks great

// s3 file upload failing could be due to IDM session timeout
// double check the user still has their session, if not, logout to update the React state with their login status
try {
await checkAuth()
Copy link
Contributor

Choose a reason for hiding this comment

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

why does checkAuth throw instead of return an error?

const [countdownSeconds, setCountdownSeconds]= useState(idleTimer.getRemainingTime() / 1000)

const handleLogoutSession = async () => {
idleTimer.message({action:'LOGOUT_SESSION'}, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

could these actions be constants?

}
}
throw Error('Cognito SignIn error')
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we used to return errors when it was an error we understood and only threw when it was something truly unexpected. I don't love turning this into something that always throws. Honestly I think since writing this we've moved towards just returning un-understood errors as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes agreed I can do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@macrael Actually looking more at this code - all of cognitoAuth throws for errors. The oddity was returning both Errors and throwing and thats why I moved it to throw to unify it and unify that interface on the frontend. What do you want to do here? Shall I make a ticket to refactor cognitoAuth?

Shall I just change this one still?

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's not going to change having to do try/catch in our pages then I don't care if you fix this one or not, but I would like to have a ticket tracking moving this to returning errors instead. My goal is that inside any of our pages/components we never have to call try/catch because anything that can throw has been wrapped up as a dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ended up rewriting cognitoAuth anyway - but there are other files that have the same issue that I left alone. Looks like we already have a ticket to address this issue - I updated it to also include adding more eslint rules.

@pearl-truss
Copy link
Contributor

pearl-truss commented Sep 16, 2024

@haworku on the review app as soon as I signed in I got a session timeout modal.

ETA But I was using toph...let me try with someone else

@pearl-truss
Copy link
Contributor

@haworku nevermind my other comment! Everything looks good if this is okay: I put my computer to sleep and when I came back to MC-Review the session timeout modal had counted down to 0:00 but stayed on the page without automatically signing me out.

Screenshot 2024-09-16 at 11 42 34 AM

@haworku
Copy link
Contributor Author

haworku commented Sep 16, 2024

@pearl-truss Thanks for catching this. It really should be logging out, I see handling in the library for this too. However, I also see open issues about what happens when computer sleep when promptBeforeIdle is in use that could be at play.

For now I added handling to modal itself to disable continue and only allow logout in cases where the countdown finishes but for some reason it does not close and logout.
Screenshot 2024-09-16 at 11 59 36 AM

What do you think?

@haworku haworku merged commit 31bba04 into main Sep 16, 2024
28 checks passed
@haworku haworku deleted the MCR-3849-sessiontimeout branch September 16, 2024 18:08
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