Fix red squiggly lines
Unanswered
Havana posted this in #help-forum
HavanaOP
How can I remove these red squigly lines:
No overload matches this call.
Overload 1 of 4, '(args_0: GetServerSidePropsContext): Promise<Session | null>', gave the following error.
Argument of type '(req: NextAuthRequest) => Response | null | undefined' is not assignable to parameter of type 'GetServerSidePropsContext'.
Overload 2 of 4, '(args_0: (req: NextAuthRequest, ctx: AppRouteHandlerFnContext) => void | Response | Promise<void | Response>): AppRouteHandlerFn', gave the following error.
Argument of type '(req: NextAuthRequest) => Response | null | undefined' is not assignable to parameter of type '(req: NextAuthRequest, ctx: AppRouteHandlerFnContext) => void | Response | Promise<void | Response>'.
Type 'Response | null | undefined' is not assignable to type 'void | Response | Promise<void | Response>'.
Type 'null' is not assignable to type 'void | Response | Promise<void | Response>'.ts(2769)
Parameter 'req' implicitly has an 'any' type.ts(7006)
(parameter) req: NextAuthRequest
import authConfig from "@/config/auth.config";
import {
apiAuthPrefix,
authRoutes,
DEFAULT_LOGIN_REDIRECT,
publicRoutes,
} from "@/routes";
import NextAuth from "next-auth";
const { auth } = NextAuth(authConfig);
export default auth((req) => {
const { nextUrl } = req;
const isLoggedIn = !!req.auth;
const isApiAuthRoute = nextUrl.pathname.startsWith(apiAuthPrefix);
const isPublicRoute = publicRoutes.includes(nextUrl.pathname);
const isAuthRoute = authRoutes.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) {
let callbackUrl = nextUrl.pathname;
if (nextUrl.search) {
callbackUrl += nextUrl.search;
}
const encodedCallbackUrl = encodeURIComponent(callbackUrl);
return Response.redirect(
new URL(`/auth/login?callbackUrl=${encodedCallbackUrl}`, nextUrl)
);
}
});
// Optionally, don't invoke Middleware on some paths
export const config = {
matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};
No overload matches this call.
Overload 1 of 4, '(args_0: GetServerSidePropsContext): Promise<Session | null>', gave the following error.
Argument of type '(req: NextAuthRequest) => Response | null | undefined' is not assignable to parameter of type 'GetServerSidePropsContext'.
Overload 2 of 4, '(args_0: (req: NextAuthRequest, ctx: AppRouteHandlerFnContext) => void | Response | Promise<void | Response>): AppRouteHandlerFn', gave the following error.
Argument of type '(req: NextAuthRequest) => Response | null | undefined' is not assignable to parameter of type '(req: NextAuthRequest, ctx: AppRouteHandlerFnContext) => void | Response | Promise<void | Response>'.
Type 'Response | null | undefined' is not assignable to type 'void | Response | Promise<void | Response>'.
Type 'null' is not assignable to type 'void | Response | Promise<void | Response>'.ts(2769)
Parameter 'req' implicitly has an 'any' type.ts(7006)
(parameter) req: NextAuthRequest