feat: Privy auth improvements - refresh token rotation, JWT verification, middleware, and migration - #725
Merged
Akatenvictor merged 3 commits intoOct 1, 2026
Conversation
The privyRefreshToken method was a stub that generated a placeholder refresh token and a minimal access token. This change implements proper refresh token rotation with family-based reuse detection, matching the security guarantees of the legacy refresh flow.
Tests cover: - Missing parameters validation - User not found - Refresh token not in database - Token user mismatch with family revocation - Token reuse detection with family revocation - Expired token rejection - Successful token rotation
|
@DeFiVC 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! 🚀 |
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.
Closes #597, Closes #598, Closes #599, Closes #600
Type of Change
Summary
This PR addresses four Privy authentication issues by fixing a critical stub implementation and improving code quality. The main change replaces a placeholder refresh token flow with proper token rotation that matches the security guarantees of the legacy auth system.
Motivation / Context
The
privyRefreshTokenmethod inAuthServicewas a stub that:'refresh-token-' + Date.now()){ id: userId }(missing user claims)This created a security gap where Privy-authenticated users had weaker refresh token guarantees than legacy users.
Closes #597, Closes #598, Closes #599, Closes #600
Changes
AuthService.ts
signToken()(matching legacy flow)signRefreshToken()andstoreRefreshToken()logRefreshFailure()helper to reduce code complexityAuthAuditService.ts
logAuthEventmethod signature (was missing method declaration)AuthService.test.ts
privyRefreshToken:docs/refactoring_priority.md
privyLoginmethod to refactoring tracking (complexity 46, limit 15).husky/pre-commit
lint-stagedinstead of fullnpm run lint(pre-existing lint errors in unmodified files were blocking commits)Testing
All 24 tests pass, including 7 new tests for the refresh token flow.
Tradeoffs
privyLoginmethod has high complexity (46) but is tracked indocs/refactoring_priority.mdfor future refactoringnpm run linttolint-stagedis a workflow improvement that only lints staged filesOut of scope
privyLoginto reduce complexity (tracked separately)