diff --git a/middleware.ts b/middleware.ts deleted file mode 100644 index cfe4e232..00000000 --- a/middleware.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { withAuth } from "next-auth/middleware"; -import { NextResponse } from "next/server"; - -export default withAuth( - function middleware(req) { - return NextResponse.next(); - }, - { - callbacks: { - authorized: ({ token, req }) => { - // Allow access to public paths - if ( - req.nextUrl.pathname === "/" || - req.nextUrl.pathname === "/signin" || - req.nextUrl.pathname.startsWith("/_next") || - req.nextUrl.pathname.startsWith("/api/auth") || - req.nextUrl.pathname.startsWith("/public") - ) { - return true; - } - - // For API routes, let the route handle its own authentication - if (req.nextUrl.pathname.startsWith('/api/')) { - // Allow access to public API endpoints - if ( - req.nextUrl.pathname.startsWith('/api/auth') || - req.nextUrl.pathname.startsWith('/api/news') - ) { - return true; - } - - // For protected API endpoints, check if the request has a valid session - if (!token) { - return false; - } - - return true; - } - - // For all other routes, require a valid token - return !!token; - }, - }, - pages: { - signIn: "/signin", - }, - } -); - -export const config = { - matcher: [ - /* - * Match all request paths except for the ones starting with: - * - api/auth (auth endpoints) - * - _next/static (static files) - * - _next/image (image optimization files) - * - favicon.ico (favicon file) - * - public folder - */ - "/((?!api/auth|_next/static|_next/image|favicon.ico|public).*)", - ], -}; \ No newline at end of file