Neah/middleware.ts
2025-04-17 13:16:16 +02:00

42 lines
1.1 KiB
TypeScript

import { withAuth } from "next-auth/middleware";
import { NextResponse } from "next/server";
export default withAuth(
function middleware(req) {
// Allow access to the root path and signin page
if (req.nextUrl.pathname === "/" || req.nextUrl.pathname === "/signin") {
return NextResponse.next();
}
// For all other routes, check authentication
return NextResponse.next();
},
{
callbacks: {
authorized: ({ token, req }) => {
// Allow access to the root path and signin page
if (req.nextUrl.pathname === "/" || req.nextUrl.pathname === "/signin") {
return true;
}
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).*)",
],
};