There is an issue with one of the overloads in this call. Overload 1 out of 4, '(args_0: GetServerSidePropsContext): Promise<Session | null>', resulted in the following error. The argument type '(req: NextAuthRequest) => Response | null' cannot be assigned to a parameter of type 'GetServerSidePropsContext'. Overload 2 out of 4, '(args_0: (req: NextAuthRequest) >> void | Response | Promise<void | Response>): AppRouteHandlerFn', caused the following error. The argument type '(req: NextAuthRequest) => Response | null' cannot be assigned to a parameter of type '(req: NextAuthRequest) >> void | Response | Promise<void | Response>'. The type 'Response | null' cannot be assigned to the type 'void | Response | Promise<void | Response>'. The type 'null' cannot be assigned to the type 'void | Response | Promise<void | Response>'.ts(2769) (parameter) req: NextAuthRequest
I encountered this error within the section: "(req) => {"
Here is the complete file:
import authConfig from "@/auth.config";
import NextAuth from "next-auth";
import {
apiAuthPrefix,
DEFAULT_LOGIN_REDIRECT,
authRoutes,
publicRoutes,
} from "@/routes";
export const { auth } = NextAuth(authConfig);
export default auth((req) => {
const { nextUrl } = req;
const isLoggedIn = !!req.auth;
const isApiAuthRoute = nextUrl.pathname.startsWith(apiAuthPrefix);
const isAuthRoute = authRoutes.includes(nextUrl.pathname);
const isPublicRoute = publicRoutes.includes(nextUrl.pathname);
if (isApiAuthRoute) {
return null;
}
if (isAuthRoute) {
if (isLoggedIn) {
return Response.redirect(new URL(DEFAULT_LOGIN_REDIRECT, nextUrl));
}
return null;
}
if (!isLoggedIn && !isPublicRoute) {
return Response.redirect(new URL("/auth/login", nextUrl));
}
return null;
});
// Optionally, don't invoke Middleware on some paths
export const config = {
matcher: ["/((?!.+\\.\\w+$|_next).*)", "/", "/(api|trpc)(.*)"],
};