Merged
Conversation
Implement-Token-Refresh-Endpoin
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.
I have successfully implemented the token refresh endpoint with all required functionality:
✅ Implementation Complete
Endpoint Created: POST /api/auth/refresh-token
Key Features Implemented:
Token Validation: Verifies JWT signature and token type
Hash Comparison: Compares provided refresh token against stored SHA-256 hash
403 Error Handling: Returns 403 for invalid/expired tokens or hash mismatches
New Access Token: Issues fresh JWT access token with user data
Refresh Token Rotation: Generates new refresh token and updates stored hash
Old Token Invalidation: Previous refresh token becomes invalid after successful refresh
Files Modified:
src/controllers/auth.controller.js - Added refreshToken function
src/routes/auth.routes.js - Added refresh token route
src/validators/auth.validators.js - Added refresh token schema validation
src/tests/auth.refresh-token.test.js - Comprehensive test suite
Test Coverage: 7 test cases covering all scenarios including valid refresh, invalid tokens, expired tokens, hash mismatches, and malformed JWTs.
The implementation follows the existing codebase patterns and maintains security best practices with proper token rotation and hash verification.
Closes #23