fix(session): Centralize signout and tokens#1774
Open
GMishx wants to merge 3 commits into
Open
Conversation
Use `dispatchSessionExpiredEvent` to hange the session expiry events centrally. This prevents from each page to check the session individually for expiry. Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
No more need of fetching raw session before making API calls. This leaves lots of room for mistakes like not checking unauthenticated user, API error 401, etc. Thus, the API calls are now divided into `AuthenticatedApiUtils` which fetches the session and token for you and `UnauthenticatedApiUtils` for APIs where authentication is not required. Also, refresh the session every 5 minutes to make sure user does not get kicked off while working on long tasks. Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
Make the session refresh interval configurable as ENV SW360_SESSION_REFETCH_INTERVAL_SECONDS Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
Member
|
Hey @GMishx ! Awesome PR ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR contains 2 focused commits to stabilize auth/session behavior and reduce auth-related code duplication.
1) Centralized signout/session-expiry handling
SessionStatusHandlerat app provider level (src/app/provider.tsx).dispatchSessionExpiredEventflow (src/utils/sessionExpiry.utils.ts) and routed session-expiry handling through one place.SessionProvidercan now be configured to have a session refresh interval withSW360_SESSION_REFETCH_INTERVAL_SECONDSwith a fallback of 5 minutes.2) API client split for authenticated vs unauthenticated calls
AuthenticatedApiUtils(src/utils/api/authenticatedApi.util.ts)UnauthenticatedApiUtils(core transport insrc/utils/api/api.util.ts)ApiUtilsinsrc/utils/index.tsto minimize broad import churn in this PR.src/utils/index.tsclarifying intended usage.Why this change
401,Important note on
ApiUtilsaliasApiUtilsalias was intentionally retained to keep this PR small and minimize broad refactoring risk.Moving forward, new/modified code should import explicitly:
AuthenticatedApiUtilsfor protected endpointsUnauthenticatedApiUtilsfor public endpointsMaintainer question
@amritkv — would you prefer I do the explicit import migration (
ApiUtils->AuthenticatedApiUtils/UnauthenticatedApiUtils) in this PR now, or keep it as a separate follow-up refactor?Testing done (local)
SessionStatusHandler.401.