Skip to content

feat: add route guards for /patient and /issuer routes#451

Merged
dev-fatima-24 merged 1 commit into
dev-fatima-24:mainfrom
Praizfotos:feat/route-guards-require-auth
Jun 2, 2026
Merged

feat: add route guards for /patient and /issuer routes#451
dev-fatima-24 merged 1 commit into
dev-fatima-24:mainfrom
Praizfotos:feat/route-guards-require-auth

Conversation

@Praizfotos
Copy link
Copy Markdown
Contributor

Summary

Add RequireAuth route guard component to protect /patient and /issuer from unauthenticated access.

Changes

  • RequireAuth component — redirects to / if not connected; accepts requiredRole prop to enforce issuer-only access on /issuer
  • AuthProvider — adds hydrating state to suppress render until localStorage session is restored, preventing flash of protected content
  • App.jsx — wraps /patient and /issuer routes with RequireAuth
  • RequireAuth.test.jsx — 9 tests covering all acceptance criteria

Acceptance Criteria

  • Navigating to /patient without a JWT redirects to /
  • Navigating to /issuer without an issuer-role JWT redirects to /
  • Redirect preserves intended destination (state.from) for post-login redirect
  • Guards re-evaluate when JWT expires (reads live context state)
  • No flash of protected content before redirect (hydrating gate)

Tested

PASS src/components/RequireAuth.test.jsx (9/9)
PASS src/hooks/useFreighter.test.jsx (5/5)

Closes #248

- Add RequireAuth component that redirects unauthenticated users to /
- Add requiredRole prop to enforce issuer-only access on /issuer
- Preserve intended destination in state.from for post-login redirect
- Add hydrating state to AuthProvider to prevent flash of protected content
- Re-evaluates on JWT expiry when auth context updates

Closes dev-fatima-24#248
@Praizfotos Praizfotos force-pushed the feat/route-guards-require-auth branch from ec50b53 to 06b1dd2 Compare June 2, 2026 11:08
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 2, 2026

@Praizfotos 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! 🚀

Learn more about application limits

@dev-fatima-24 dev-fatima-24 merged commit ed3bc47 into dev-fatima-24:main Jun 2, 2026
4 of 19 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.

[FRONTEND] Add route guards for authenticated pages

2 participants