Upstash ratelimit & next auth in middleware
Unanswered
Collin posted this in #help-forum
CollinOP
Hi i'm trying to get upstash ratelimit and nextauth in 1 middleware.ts file but cant get it to work, can someone help me?
9 Replies
CollinOP
I'm trying to combine:
With
import { NextFetchEvent, NextRequest, NextResponse } from "next/server";
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
const redis = new Redis({
url: "",
token: ""
});
const ratelimit = new Ratelimit({
redis: redis,
limiter: Ratelimit.slidingWindow(5, "10 s"),
});
export default async function middleware(
request: NextRequest,
event: NextFetchEvent,
): Promise<Response | undefined> {
const ip = request.ip ?? "127.0.0.1";
const { success, pending, limit, reset, remaining } =
await ratelimit.limit(ip);
return success
? NextResponse.next()
: NextResponse.redirect(new URL("/blocked", request.url));
}
export const config = {
matcher: "/",
};With
export { default } from "next-auth/middleware";
export const config = { matcher: ["/dashboard/:path*"] };American Chinchilla
What error do you get
CollinOP
@American Chinchilla
American Chinchilla
Maybe because you cant have two default
When you hover over
The red error lines
What message does it say?
CollinOP
That you cant have 2 defaults but i dont know how to merge them