Description
app/api/auth/wallet/route.ts issues a 15-minute access token (expiresIn: "15m") with no refresh path, so authenticated sessions hard-expire mid-flow during long stream operations. Add a backend refresh mechanism so clients can obtain a new short-lived access token without re-signing a wallet challenge each time. This is a server-side session-security feature.
Requirements and Context
- Introduce
POST /api/auth/refresh issuing a new 15-minute access token from a longer-lived, rotating refresh token.
- Refresh tokens must be revocable and stored server-side (in
app/lib/db.ts mock store, keyed by actorId), with rotation-on-use to detect reuse.
- Reuse the existing JWT signing/verification utilities from
app/lib/auth.ts.
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested Execution
- Fork the repo and create a branch
git checkout -b feature/wallet-jwt-refresh
- Implement changes
app/api/auth/refresh/route.ts (new)
app/lib/auth.ts — refresh-token issue/verify/rotate helpers
app/lib/db.ts — refresh-token store and revocation set
- Test and commit
npm test -- app/api/auth app/lib/auth.test.ts
- Cover edge cases: reused (rotated) refresh token, revoked token, expired refresh
- Include test output and notes in the PR
Example commit message
feat: add rotating refresh-token flow for wallet sessions
Acceptance Criteria
Guidelines
- Minimum 90% test coverage including reuse/revocation paths
- Clear documentation and inline comments
- Timeframe: 96 hours
Description
app/api/auth/wallet/route.tsissues a 15-minute access token (expiresIn: "15m") with no refresh path, so authenticated sessions hard-expire mid-flow during long stream operations. Add a backend refresh mechanism so clients can obtain a new short-lived access token without re-signing a wallet challenge each time. This is a server-side session-security feature.Requirements and Context
POST /api/auth/refreshissuing a new 15-minute access token from a longer-lived, rotating refresh token.app/lib/db.tsmock store, keyed byactorId), with rotation-on-use to detect reuse.app/lib/auth.ts.Suggested Execution
app/api/auth/refresh/route.ts(new)app/lib/auth.ts— refresh-token issue/verify/rotate helpersapp/lib/db.ts— refresh-token store and revocation setnpm test -- app/api/auth app/lib/auth.test.tsExample commit message
Acceptance Criteria
POST /api/auth/refreshreturns a fresh access token + rotated refresh tokenGuidelines