The NextResponse.rewrite
function proxies requests, so the url shouldn't change. Using NextResponse.redirect
worked for me:
import { NextResponse } from "next/server";
export function middleware(req) {
const nextUrl = req.nextUrl;
if (nextUrl.searchParams.has("verification_token")) {
nextUrl.searchParams.delete("verification_token");
return NextResponse.redirect(nextUrl);
} else {
return NextResponse.next();
}
}