upstash/ratelimit-js

Next Middleware new signature

Closed this issue · 4 comments

I'm getting this error

error - node_modules/next/dist/server/web/spec-extension/response.js (18:0) @ handleMiddlewareField
error - The middleware "/src/middleware" accepts an async API directly with the form:

export function middleware(request, event) {
    return NextResponse.redirect('/new-location')
}

Read more: https://nextjs.org/docs/messages/middleware-new-signature

But changing NextResponse.next(request) -> NextResponse.next() and NextResponse.rewrite(new URL("/api/blocked", request.url), request) -> NextResponse.rewrite(new URL("/api/blocked", request.url)) fixed the error.

Hey @csulit can you share a code snippet of using @upstash/ratelimit where this happens?
Thank you!

Or is this about an example being broken?

@chronark The (middleware.ts) example is not working with next version 13.0.7

This line

  const response = success
    ? NextResponse.next(request)
    : NextResponse.rewrite(new URL("/api/blocked", request.url), request);

Works fine with next 12

ok thank you, I'll fix that