Skip to content

Add refresh-token / silent re-auth flow for 15-minute wallet JWTs #224

@greatest0fallt1me

Description

@greatest0fallt1me

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

  1. Fork the repo and create a branch
    git checkout -b feature/wallet-jwt-refresh
  2. 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
  3. 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

  • POST /api/auth/refresh returns a fresh access token + rotated refresh token
  • Reused refresh token is rejected and revokes the chain
  • Audit event recorded for refresh and revoke
  • Coverage ≥ 90% for the new code

Guidelines

  • Minimum 90% test coverage including reuse/revocation paths
  • Clear documentation and inline comments
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programapiAPI endpoint/contract workbackendBackend service workenhancementNew feature or improvementsecuritySecurity hardening
No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions