T3.2: Wire up Next.js middleware for role-based route protection - #91
Merged
Conversation
…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
Taleef7
approved these changes
Feb 23, 2026
Contributor
There was a problem hiding this comment.
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.tstomiddleware.tsand the exported function fromproxytomiddleware, activating Next.js edge middleware - Updated README.md structure tree and feature status table to reference
middleware.tsinstead ofproxy.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.
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.
Route protection logic existed in
proxy.tsbut was never invoked — Next.js only recognizesmiddleware.tsat the project root with amiddlewareexport. All protected routes (/dashboard,/tutor,/admin) were effectively unguarded at the edge.Changes
middleware.ts— renamesproxy.ts→middleware.tsand the exported function fromproxytomiddleware, making it a valid Next.js edge middleware. Logic is unchanged:/dashboard/**,/tutor/**,/admin/**→/auth/sign-in?next=<path>/auth/sign-inor/auth/sign-up→/dashboardproxy.ts— dead code, never imported or executedREADME.md— corrected repo structure tree and feature status table to referencemiddleware.tsRole-specific server-side checks (already implemented) remain in place as the second layer:
app/dashboard/page.tsx— readsprimary_role, redirects admin/tutor to their areasapp/admin/layout.tsx— verifiesadminrole via service-role clientapp/tutor/layout.tsx— verifiestutororadminrole via service-role clientTesting
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.