Implement JWT refresh token flow for long-running uploads#23
Open
Copilot wants to merge 3 commits into
Open
Conversation
3 tasks
Agent-Logs-Url: https://github.com/ANURA4G/package-system/sessions/5f6c3fdd-f181-4929-8c31-dff96c3aac5b Co-authored-by: chandru07072007 <198200487+chandru07072007@users.noreply.github.com>
…offset Agent-Logs-Url: https://github.com/ANURA4G/package-system/sessions/5f6c3fdd-f181-4929-8c31-dff96c3aac5b Co-authored-by: chandru07072007 <198200487+chandru07072007@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement JWT refresh token flow for long-running uploads
Implement JWT refresh token flow for long-running uploads
Apr 14, 2026
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.
Access token expiry mid-upload caused abrupt 401 failures and lost progress. This adds a full refresh token flow with silent renewal, token rotation, and upload pause-on-auth-failure instead of hard abort.
Backend
config.py: Two new required settings —REFRESH_TOKEN_SECRET_KEY(separate secret, strength-validated) andREFRESH_TOKEN_EXPIRE_DAYS(default 30)auth.py:create_refresh_token()/decode_refresh_token()using a dedicated secret; access and refresh tokens now carry a"type"claim;verify_token()rejects non-access tokensdatabase.py:refresh_tokens_collectionwith TTL auto-expiry and unique hash indexauth_routes.py:POST /login— issues access token + HttpOnlyrefresh_tokencookie; response includesexpires_inPOST /refresh— verifies token against DB hash, rotates (deletes old, inserts new), returns new access tokenPOST /logout— revokes DB entry, clears cookiedatetime.utcnow()replaced with timezone-awaredatetime.now(timezone.utc)Frontend
storage.js:storeAuthSession(token, expiresIn),getAccessToken(),getTokenExpiresAt(),clearAuthSession()— centralizes session state away from rawsessionStoragecallsauthApi.js:silentRefresh()with single-flight deduplication; 401-retry response interceptor skips/refreshand/loginto avoid loops;logoutUser()calls backend before clearing local stateuploadApi.js:withCredentials: true+ same 401-retry interceptor wired tosilentRefreshuseChunkedUpload.js: Auth failures now attemptsilentRefresh()then pause the upload instead of throwing to error state — progress is preserved, user can re-authenticate and resumeApp.jsx: Proactive refresh timer firesREFRESH_BEFORE_EXPIRY_MS(2 min) before token expiry;handleLogoutcallslogoutUser()+clearAuthSession(); auth error toast no longer forces logout when upload is paused