feat: add /api/v1/auth/me endpoint for token freshness introspection (Closes #382) - #534
Open
waterWang wants to merge 2 commits into
Open
feat: add /api/v1/auth/me endpoint for token freshness introspection (Closes #382)#534waterWang wants to merge 2 commits into
waterWang wants to merge 2 commits into
Conversation
…es [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]
…loses BountyOnChain#382) Backend: - Add GET /api/v1/auth/me endpoint protected by JwtAuthGuard - Returns { address, expiresAt } from the authenticated JWT token - Update JwtStrategy to expose exp claim for the me endpoint Frontend: - getAccessToken() now calls /api/v1/auth/me to check token freshness - Skips re-auth when token has >60s TTL remaining - Falls back to re-auth when token is stale or network error Tests: - Update api.spec.ts to mock /me endpoint calls - Update api.spec.tsx to verify /me is called on saved-token path
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
Adds a new
GET /api/v1/auth/meendpoint that returns the authenticated user's Stellar address and token expiration time. The frontendgetAccessToken()now consults this endpoint before requesting a new challenge, skipping the full re-auth flow when the existing token has more than 60 seconds of TTL remaining.Backend Changes
GET /api/v1/auth/meendpoint inauth.controller.ts— protected byJwtAuthGuard, returns{ address, expiresAt }JwtStrategy.validate()to also return theexpclaim from the JWT payloadFrontend Changes
getAccessToken()inlib/api.ts:/api/v1/auth/meto check freshnessTests
api.spec.tsto mock the/meendpoint and verify the new flowapi.spec.tsxto verify that the saved-token path calls/mefor freshnessAcceptance Criteria
/meendpoint)getAccessToken()skips re-auth when >60s TTL remainsCloses #382