Skip to content

[FE-02] Enforce auth on admin routes via Next.js middleware - #306

Merged
Leothosine merged 2 commits into
tosirano:mainfrom
bellabuks:feat/fe-02-nextjs-middleware-auth
Jul 19, 2026
Merged

[FE-02] Enforce auth on admin routes via Next.js middleware#306
Leothosine merged 2 commits into
tosirano:mainfrom
bellabuks:feat/fe-02-nextjs-middleware-auth

Conversation

@bellabuks

Copy link
Copy Markdown
Contributor

Summary

Replaces the bypassable client-only ProtectedRoute guard with a server-side Next.js middleware that enforces authentication and role checks before any page content is delivered to the browser.

Changes

  • frontend/middleware.ts intercepts all /admin/* requests
  • Reads the accessToken cookie and verifies it with jose (jwtVerify + JWT_SECRET)
  • Redirects unauthenticated requests to /login?redirect={originalPath}
  • Clears stale cookie on token expiry before redirecting
  • Enforces role-based access via ROUTE_ROLE_MAP (e.g. /admin/settings requires super_admin)
  • Redirects role-violations to /admin/dashboard instead of showing a blank screen
  • Matcher config excludes _next/static, _next/image, favicon.ico, and all static assets

closes #270

- Add `jose` to frontend/package.json; Next.js middleware imports
  jwtVerify from jose which was missing from dependencies
- Update ethnum 1.5.2 -> 1.5.3 in contracts/Cargo.lock to fix
  transmute size mismatch build error on stable Rust

@Leothosine Leothosine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice work

@Leothosine
Leothosine merged commit f68a2c6 into tosirano:main Jul 19, 2026
3 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.

[FE-02] Enforce auth on admin routes via Next.js middleware - client-only guard is bypassable

2 participants