fix: JWT refresh tokens, configurable CORS origins, cache test relocation (#275, #274, #272) - #454
Merged
DeFiVC merged 2 commits intoAug 31, 2026
Conversation
…tion Batch of three independent fixes: ChainLearnOfficial#275 - Implement JWT refresh token mechanism (API side) - POST /auth/refresh: validates + rotates refresh token, single-use via Redis GETDEL, returns new access token - 7-day refresh token expiry, 24h access token unchanged - Reuse detection revokes the entire rotation family (theft response) - Redis-backed storage (opaque sha256 token hash), matching existing SEP-10/JWT-denylist conventions in this repo - logout optionally revokes the sent refresh token's family - Frontend wiring not included (no frontend repo present) ChainLearnOfficial#274 - Configure CORS origins via environment variable - CORS_ORIGINS env var, comma-separated, parsed to trimmed array - Unset behavior unchanged: localhost:3000 (dev) / chainlearn.io (prod) ChainLearnOfficial#272 - Move cache test files to tests/unit/ - Moved the 3 files named in the issue; src/test/ still holds 9 unlisted files (see PR description for scope note) ChainLearnOfficial#273 not included: target file lives in chainlearn-contracts, not in this repo. Verified: lint (0 errors), typecheck (0 new errors vs. baseline), full test suite (new/touched tests pass, no regressions).
|
@Cyber-Mitch Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
5 tasks
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
Batch of three fixes from a four-issue backlog. #273 is not actionable in this repo (target file lives in
chainlearn-contracts, not present here). #275's frontend half is similarly out of scope (no frontend repo present) — API side is complete.#275 — JWT refresh token mechanism (API side)
Adds refresh-token issuance, rotation, and reuse-detection alongside the existing 24h access token.
POST /auth/refresh: validates refresh token, returns new access token, rotates the refresh token (single-use, atomic via RedisGETDEL)sha256(token)keys, no raw tokens stored), matching this repo's existing SEP-10/JWT-denylist conventions rather than adding a new Postgres tablelogoutoptionally revokes the sent refresh token's family alongside the existing access-token denylistingKnown limitations (flagged, not fixed here):
/auth/refreshdoesn't re-check banned/deleted user state — relies onauthGuardat the next requestsrc/lib/api/auth.ts,client.ts) not done — no frontend repo present in this environmentCloses #275 (API side)
#274 — Configurable CORS origins
CORS_ORIGINSenv var added to config schema (comma-separated, parsed to a trimmed array). Unset behavior is identical to today:["http://localhost:3000"]in dev,["https://chainlearn.io"]in prod. No existing chainlearn-indexerALLOWED_ORIGINSconvention was available to match in this repo, so followed the repo's own idioms (zod.transform, module-level derived const).Files:
src/config/index.ts,src/server.ts,.env.exampleCloses #274
#272 — Move cache test files to tests/unit/
Moved exactly the 3 files named in the issue (
cache.test.ts,course-cache-and-progress.test.ts,quiz-grading-and-warming.test.ts) fromsrc/test/totests/unit/, with import paths updated accordingly.Note on scope:
src/test/still contains 9 other test files not listed in the issue. Per the issue's literal scope, only the 3 named files were moved — the acceptance criterion "no test files remain insrc/test/" is not fully met as a result. Flagging this explicitly rather than silently expanding scope; happy to move the remainder in a follow-up if that's the intent.Closes #272 (partial — see note above)
closes #273
Verification
npm run lintnpm run typechecknpm test[fill in actual counts once the re-verification in step 5 completes]
Follow-ups (flagged, not fixed here — out of scope for this batch)
src/server.ts:79—logger:→loggerInstance:(Fastify 5 requirement); currently breaks ~15 e2e/buildApp test suitessrc/modules/courses/course.service.ts:1434— missing"course.archived"inAuditEventunion; breaksnpm run buildtests/unit/tracing.test.ts:32— bad relative import path#272— remaining 9 files insrc/test/not moved (see note above)#275hardening — optional "logout all devices", user-state re-check in/auth/refresh