Skip to content

feat: add /api/v1/auth/me endpoint for token freshness introspection (Closes #382) - #534

Open
waterWang wants to merge 2 commits into
BountyOnChain:mainfrom
waterWang:feat/me-endpoint
Open

feat: add /api/v1/auth/me endpoint for token freshness introspection (Closes #382)#534
waterWang wants to merge 2 commits into
BountyOnChain:mainfrom
waterWang:feat/me-endpoint

Conversation

@waterWang

Copy link
Copy Markdown

Summary

Adds a new GET /api/v1/auth/me endpoint that returns the authenticated user's Stellar address and token expiration time. The frontend getAccessToken() 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

  • New GET /api/v1/auth/me endpoint in auth.controller.ts — protected by JwtAuthGuard, returns { address, expiresAt }
  • Updated JwtStrategy.validate() to also return the exp claim from the JWT payload

Frontend Changes

  • Updated getAccessToken() in lib/api.ts:
    • When a saved token exists and matches the public key, calls /api/v1/auth/me to check freshness
    • If >60s TTL remaining → returns the existing token (no re-auth)
    • If <60s TTL or network error → clears the token and re-authenticates

Tests

  • Updated api.spec.ts to mock the /me endpoint and verify the new flow
  • Updated api.spec.tsx to verify that the saved-token path calls /me for freshness

Acceptance Criteria

  • Unit test for token freshness returns correctly (via /me endpoint)
  • Frontend getAccessToken() skips re-auth when >60s TTL remains

Closes #382

waterWang and others added 2 commits July 28, 2026 12:29
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[S-B] Add a me endpoint that returns the JWT subject and freshness

1 participant