Skip to content

Conversation

@tusharshah21
Copy link
Collaborator

@tusharshah21 tusharshah21 commented Dec 18, 2025

Create JWT storage utility for token management (localStorage)

  • Implement useLogin hook for SIWE signature + JWT token request
  • Add useAuthHeader hook for token refresh and header management
  • Create enhanced fetch wrapper with JWT and 401 auto-retry support
  • Add LoginButton component (Sign In/Logout) in header next to ConnectButton
  • Update profile hooks to support JWT with SIWE fallback:
    • useCreateProfile
    • useUpdateProfile
    • useDeleteProfile

Features:

  • Users can sign once with SIWE message to get JWT token
  • Token automatically included in all protected API requests
  • No need to sign every request anymore
  • On 401, automatically refreshes token and retries request
  • Token persists across page reloads
  • Graceful fallback to SIWE signature auth if no token

Closes #150

Copy link
Contributor

@joelamouche joelamouche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great, but where is the logic for token expiration (defaults to 86400 in our backend)? Yu should probably store date in localstorage and use it to see if token expired

@tusharshah21 tusharshah21 force-pushed the feat-#150-jwt-frontend branch from 4d48428 to 179ed04 Compare December 22, 2025 16:44
@tusharshah21
Copy link
Collaborator Author

Thanks for the feedback! Both issues addressed:

  1. Token Expiration: Now storing expiration timestamp (defaults to 86400s) in localStorage. isTokenValid() checks expiration and auto-clears expired tokens.
  2. Unused fetchWithJWT: Removed - wasn't being used. Profile hooks use simpler direct fetch with conditional JWT/SIWE headers.

Copy link
Contributor

@joelamouche joelamouche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice progress!
But there is still some work in order to provide a clean Log In UX and completely replace siwe with jwt

@tusharshah21 tusharshah21 force-pushed the feat-#150-jwt-frontend branch from ab700fe to be70264 Compare December 23, 2025 16:08
@tusharshah21
Copy link
Collaborator Author

All profile CRUD operations now:

  • Auto-trigger login when token is missing/expired
  • Use JWT-only (no signature prompts in dialogs)
  • Handle authentication transparently in hooks

Removed all SIWE signing UI from Create/Edit/Delete dialogs. Users now sign once on login, then all operations use the JWT token seamlessly.

@joelamouche
Copy link
Contributor

Okay looks great! 🚀

Copy link
Contributor

@joelamouche joelamouche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🌔

@joelamouche joelamouche merged commit b3e299f into TheSoftwareDevGuild:main Jan 5, 2026
4 checks passed
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.

Implement JWT - Front end flow

2 participants