-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
22 lines (20 loc) · 802 Bytes
/
Copy pathproxy.ts
File metadata and controls
22 lines (20 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { NextResponse, type NextRequest } from "next/server";
import { updateSession } from "@/lib/supabase/middleware";
import { rateLimit, clientIp } from "@/lib/rate-limit";
export async function proxy(request: NextRequest) {
const path = request.nextUrl.pathname;
if (path.startsWith("/auth/signin") || path.startsWith("/auth/callback")) {
const ip = clientIp(request);
const r = rateLimit(`auth:${ip}`, 10, 60_000);
if (!r.ok) {
return new NextResponse("Too many sign-in attempts. Try again in a minute.", {
status: 429,
headers: { "Retry-After": String(r.retryAfter) },
});
}
}
return await updateSession(request);
}
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)"],
};