Skip to content

T3.2: Wire up Next.js middleware for role-based route protection - #91

Merged
Taleef7 merged 2 commits into
mainfrom
copilot/verify-role-based-routing
Feb 23, 2026
Merged

T3.2: Wire up Next.js middleware for role-based route protection#91
Taleef7 merged 2 commits into
mainfrom
copilot/verify-role-based-routing

Conversation

Copilot AI commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Route protection logic existed in proxy.ts but was never invoked — Next.js only recognizes middleware.ts at the project root with a middleware export. All protected routes (/dashboard, /tutor, /admin) were effectively unguarded at the edge.

Changes

  • Created middleware.ts — renames proxy.tsmiddleware.ts and the exported function from proxy to middleware, making it a valid Next.js edge middleware. Logic is unchanged:
    • Unauthenticated requests to /dashboard/**, /tutor/**, /admin/**/auth/sign-in?next=<path>
    • Authenticated users hitting /auth/sign-in or /auth/sign-up/dashboard
  • Removed proxy.ts — dead code, never imported or executed
  • Updated README.md — corrected repo structure tree and feature status table to reference middleware.ts

Role-specific server-side checks (already implemented) remain in place as the second layer:

  • app/dashboard/page.tsx — reads primary_role, redirects admin/tutor to their areas
  • app/admin/layout.tsx — verifies admin role via service-role client
  • app/tutor/layout.tsx — verifies tutor or admin role via service-role client

Testing

  • Verified locally
  • Checked key flows manually

Notes

The middleware handles the fast edge-level unauthenticated guard. Fine-grained wrong-role redirects are intentionally handled in Server Components (layouts/pages) where the Supabase service-role client is available.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ad proxy.ts

Co-authored-by: Taleef7 <89072337+Taleef7@users.noreply.github.com>
Copilot AI changed the title [WIP] Verify implementation of role-based route protection T3.2: Wire up Next.js middleware for role-based route protection Feb 23, 2026
Copilot AI requested a review from Taleef7 February 23, 2026 18:32
@Taleef7
Taleef7 marked this pull request as ready for review February 23, 2026 18:53
Copilot AI review requested due to automatic review settings February 23, 2026 18:53

Copilot AI 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.

Pull request overview

This PR fixes a critical security issue where route protection logic existed in proxy.ts but was never executed because Next.js only recognizes edge middleware when the function is named middleware and exported from middleware.ts at the project root. The PR renames the file and function to follow Next.js conventions, making the authentication-based route protection operational at the edge.

Changes:

  • Renamed proxy.ts to middleware.ts and the exported function from proxy to middleware, activating Next.js edge middleware
  • Updated README.md structure tree and feature status table to reference middleware.ts instead of proxy.ts

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
middleware.ts Renamed function export from proxy to middleware and updated comment to reflect "role-based route protection" instead of mentioning "Next.js 16"
README.md Updated repo structure tree to include middleware.ts and corrected feature status table entry from "Route protection (proxy)" to "Route protection (middleware)"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Taleef7
Taleef7 merged commit f308aa3 into main Feb 23, 2026
5 checks passed
@Taleef7
Taleef7 deleted the copilot/verify-role-based-routing branch February 23, 2026 18:59
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.

3 participants