feat: add role-aware navigation and protected route guards - #1071
Merged
Junirezz merged 1 commit intoJul 29, 2026
Conversation
Resolve a client-side UserRole (guest/investor/admin) from the connected wallet address via a VITE_ADMIN_WALLETS allowlist, gate the nav's Admin link and a new /admin route behind it with a reusable ProtectedRoute guard, and document the pattern for adding future gated routes. Closes Junirezz#981
|
@Awosdot 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! 🚀 |
3 tasks
3 tasks
Francis6-git
pushed a commit
to Francis6-git/YieldVault-RWA
that referenced
this pull request
Jul 30, 2026
…edirect ProtectedRoute (Junirezz#1071, Junirezz#981) already redirects a disallowed role away from a guarded route and stashes the attempted path in location.state.from "so a future redirect target can restore it later" — but nothing ever read that state, so a user who tried /admin and later connected the admin wallet just stayed on the page they'd been bounced to instead of landing back on /admin. Add useRestoreGuardedRoute(role), called from App.tsx whenever role changes. It tries the stashed `from` path once per role transition: if the new role is allowed, the user lands where they originally tried to go; if not, ProtectedRoute guards it again (role hasn't changed, so the hook won't re-fire), avoiding a redirect loop. Related to Junirezz#1040, which duplicates Junirezz#981, already resolved by Junirezz#1071 for the role/nav/guard scaffolding this builds on.
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.
Closes #981
Security Testing
Test Coverage
frontend/src/lib/roles.test.ts(role resolution, allowlist parsing/matching)frontend/src/components/ProtectedRoute.test.tsx(allow/redirect behavior, custom redirect target)frontend/src/components/Navbar.test.tsx(Admin link visibility per role, existing assertions untouched)npm run build: clean before and afternpm run lint: 0 errors / 5 pre-existing warnings, identical before and afternpm run test:run: 718 passed / 1 pre-existing failure (VaultComparison.test.tsx, unrelated to this change) before → 732 passed / same 1 pre-existing failure after. All 14 new tests pass; no regressions.🚀 Deployment Notes
No infrastructure or deployment changes required. A new optional env var,
VITE_ADMIN_WALLETS(comma-separated wallet addresses), was added to.env.example,.env.local.example,.env.production.example, anddocs/ENV_VARIABLE_MATRIX.md. Leaving it unset disables the admin role for everyone — fully backward compatible.Mainnet Readiness
Breaking Changes
None.
Navbar's newroleprop defaults to"guest", so existing callers/tests are unaffected.📊 Automated Scan Results
Slither Analysis
Related Documentation
frontend/ROLE_BASED_NAVIGATION.md— role model, nav visibility, route guard usage, and how to add a new gated route.✅ Reviewer Checklist
adminrole must still enforce authorization server-side📋 Pre-Submit Checklist
npm test(except the one pre-existing, unrelated failure noted above)npm run lint