Skip to content

feat: restore the originally-attempted route after a ProtectedRoute redirect - #1101

Merged
Junirezz merged 1 commit into
Junirezz:mainfrom
esthertitilayo-dev:feat/1040-protected-route-redirect-back
Jul 29, 2026
Merged

feat: restore the originally-attempted route after a ProtectedRoute redirect#1101
Junirezz merged 1 commit into
Junirezz:mainfrom
esthertitilayo-dev:feat/1040-protected-route-redirect-back

Conversation

@esthertitilayo-dev

Copy link
Copy Markdown
Contributor

Summary

Closes #1040.

Heads up for reviewers: #1040's title is an exact duplicate of #981, resolved by #1071 — merged less than a day before this PR was opened. That PR built the whole role-aware nav/guard system (roles.ts, ProtectedRoute, admin nav gating, docs, tests). This PR doesn't re-build any of that; it finishes one specific piece ProtectedRoute's own doc comment already promised but never delivered:

"The attempted path is passed along in location state so the redirect target can restore it later."

Nothing ever consumed that location.state.from. A guest bounced away from /admin who later connected the admin wallet just stayed on / instead of landing back on /admin.

Added 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 — since role hasn't changed, the hook won't re-fire, so there's no redirect loop. Updated ROLE_BASED_NAVIGATION.md to document the completed behavior.

Test plan

  • Added useRestoreGuardedRoute.test.tsx (covers: no stashed path → no-op, role already allowed → restores immediately, role still disallowed → stays put without looping, role changes to allowed → restores)
  • Re-ran ProtectedRoute.test.tsx and roles.test.ts — still passing, no behavior change to existing guard logic
  • npx tsc -b — no new type errors (one pre-existing, unrelated ToastCenter.tsx error present on main before this change too)

🤖 Generated with Claude Code

…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.
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@esthertitilayo-dev 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

@Junirezz
Junirezz merged commit 18bac04 into Junirezz:main Jul 29, 2026
18 of 24 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 role-aware navigation and protected route guards

2 participants