© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
1 reply
ismael1234

Protecting routes with Nextjs Middleware

I tried adding this code from supabase website:

import { withMiddlewareAuth } from '@supabase/auth-helpers-nextjs'

export const middleware = withMiddlewareAuth({ redirectTo: '/login' })

export const config = {
  matcher: ['/middleware-protected/:path*'],
}
import { withMiddlewareAuth } from '@supabase/auth-helpers-nextjs'

export const middleware = withMiddlewareAuth({ redirectTo: '/login' })

export const config = {
  matcher: ['/middleware-protected/:path*'],
}


in the file "middleware.ts" inside pages, also tried after in "_middleware.ts", and doesn't work. In the first file it doesn't do anything, in the second one it gives me many errors. Changing /middleware-protected/:path* to "comments or /" for example doesn't do anything.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Nextjs with google provider (protected routes)
SupabaseSSupabase / help-and-questions
4y ago
Protect routes in nextjs
SupabaseSSupabase / help-and-questions
4y ago
Nextjs auth-helpers with middleware and magiclinks
SupabaseSSupabase / help-and-questions
4y ago
protecting routes using auth.getUser causes "Request rate limit reached"
SupabaseSSupabase / help-and-questions
13mo ago