Skip to content

Middleware

Stelo CMS uses Next.js middleware for authentication, access control, and internationalization.

Protects admin routes and API endpoints:

middleware.ts
export function middleware(request: NextRequest) {
// Authentication check
if (isAdminRoute(request.nextUrl.pathname)) {
return withAuth(request);
}
// Internationalization
return withI18n(request);
}

Role-based access control for different areas:

  • Admin panel access
  • API endpoint protection
  • Content visibility rules

Automatic locale detection and routing:

  • URL-based locale detection
  • Cookie-based locale preference
  • Automatic redirects

Protection against abuse:

  • API rate limiting
  • Authentication attempt limits
  • File upload restrictions
export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico).*)',
'/api/(.*)'
]
};

This section will be expanded with detailed implementation examples.