Fix for premature session expiration #402
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Your checklist for this pull request
What is the current behaviour?
Multiple MWDB users are reporting problems with unexpected session expiration during normal usage or after leaving the MWDB opened for a longer time.
This is pretty annoying and is caused by few flaws in client-side code that handles authentication.
What is the new behaviour?
This PR applies few fixes:
Webapp periodically refreshes the session to prevent expiration when tab is opened for a longer time. Unfortunately, that mechanism caused the opposite effect, because there are huge chances that some of
/api/refreshrequests will fail after multiple periodic calls, causing the logout. Changed handling of that situation from logout to silent error reported in console. If session has really expired, user will be notified anyway via HTTP 401 handling.There was a race-condition on mount: some API requests were sent on component mount before the authorization token is set in Axios request headers. That situation results in HTTP 401 and logout even if correct session token is available in localStorage. Added
useAxiosEffectto setup interceptors and headers as a part of initial render (like componentWillMount), so Axios will be set-up first.getStoredAuthSessionhaven't checked for emptyuserkey in localStorage, which results in error reported in dev console. Added proper check.Test plan