Next.js Discord

Discord Forum

I can't response into a server action from middleware

Unanswered
Polar bear posted this in #help-forum
Open in Discord
Polar bearOP
export async function middleware(request: NextRequest) {
    const NEXT_ACTION = headers().get("next-action")

    if (NEXT_ACTION === ContactActions.Mail) {
        console.log("Is mail servera ction")
        return NextResponse.json({
            status: "error",
            message: "You have reached the limit"
        }, { status: 429 })
    }
}

export const config = {
    matcher: '/:path*',
}


I'm trying to do some kind of ratelimiting but I coudn't respond to server actions from middleware to access it in the form and getting undefined

6 Replies

My problem is I can't overwrite the response of the server action
I want the server action to respond with rate limit response instead of responding with it's normal response
@Polar bear My problem is I can't overwrite the response of the server action
is your if statement triggering tho
Polar bearOP
Yes