Next.js Discord

Discord Forum

Next auth, how to include custom middleware with auth middleware?

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
export async function middleware(request: NextRequest) {
    const response = NextResponse.next();
    // csrf protection
    const csrfError = await csrfProtect(request, response);

    const pathname = new URL(request.url).pathname

    if (excludedRoutes.includes(pathname)) {
        return response;
    }

    // check result
    if (csrfError) {
        return new NextResponse('invalid csrf token', { status: 403 });
    }

    return response;
}

export { default } from "next-auth/middleware"
this does not seem to return with next-auth, so how do i include the middleware above?

0 Replies