Supabase rate limiting for a Next.js app: Auth, Postgres and Edge layers, 2026
Supabase limits Auth by default, not your own writes or routes. Add limits in Postgres, Edge Functions and Next.js, keyed on user ID or IP.

Direct answer
Supabase rate limits Auth for you, but it does not limit your own tables, Edge Functions or Next.js routes. Add limits at three layers: tune the built-in Auth limits, count writes in Postgres or an Edge Function, and throttle your Next.js route handlers with a shared store. Key each limit on the user ID when someone is signed in and on the IP address when they are not.
Below, each layer gets the numbers from the official documentation, as of November 2026.
Know what Supabase already limits
Supabase's Auth rate limits page lists the defaults. When a client exceeds one, Auth returns a 429 Too Many Requests error. The ones that matter most for a Next.js app:
- Sign-ups and sign-ins (including
/recover,/resend,/magiclink,/otpand/user): 30 requests per 5 minutes, with bursts up to 30. Anonymous sign-ins are excluded from this bucket. - Anonymous sign-ins: 30 per hour, per IP.
- Token endpoint (including refresh token grants): 150 requests per 5 minutes, with bursts up to 30.
- Email sent with the built-in provider: 2 per hour. Raising it requires custom SMTP or the Send Email hook.
- MFA challenge and verify: 15 requests per minute. This one is not configurable.
Most of the others can be changed under Authentication, then Rate Limits, in the dashboard, or through the Management API.
Two gaps follow from this list. Auth limits say nothing about the rows your app writes after login. And the 2 emails per hour on the built-in provider will break a real sign-up flow long before an attacker does, so plan for custom SMTP early. If you are still wiring up sessions, our guide to server-side sessions in Next.js covers the part that sits before any of this.
Limit writes in Postgres with a pre-request function
Row Level Security decides who may touch a row. It does not decide how often. The Securing your API guide shows a pre-request function for this: a Postgres function that PostgREST runs before it serves each Data API request.
The setup has four moving parts:
- A function, called
public.check_requestin the guide, that reads the request and decides whether to allow it. - A setting that points the
authenticatorrole at it throughpgrst.db_pre_request. - A
notify pgrst, 'reload config'so PostgREST picks up the change. - A table in a
privateschema, such asprivate.rate_limits, that stores the IP and timestamp of each write. Keeping it out of the exposed schemas keeps it off the Data API.
The guide's example rejects an IP after more than 100 write requests in 5 minutes. It raises an exception with SQLSTATE PGRST and a JSON body, which lets you choose the HTTP status. It recommends a pg_cron job to delete old rows, so the table does not grow without bound.
Know three limits before you rely on it:
- Writes only. Only POST, PUT, PATCH and DELETE can be rate limited. GET and HEAD requests run in read-only mode and may be served by read replicas, which cannot write counters.
- Data API only. The setting does not cover Realtime, Storage or other Supabase products. For those, the guide says to call the function inside RLS policies, and notes this can affect performance because it is evaluated per row.
- The IP comes from a header. The example reads
x-forwarded-forfromrequest.headersand takes the first address. The guide does not say whether a client can spoof that value, so check how your proxy sets it before you enforce anything on it.
Limit Edge Functions with Redis
If your logic lives in Edge Functions, a Postgres counter is the wrong tool. Supabase's rate limiting example for Edge Functions uses Redis instead. Redis is built for atomic operations such as incrementing a value, which is exactly what a request counter does, and the limit can be keyed to the user ID from Supabase Auth.
The example uses Upstash, whose Redis client talks over HTTP and REST. That matters in serverless and Edge runtimes, where you cannot hold a long-lived TCP connection. Supabase links a working function in its examples repository under examples/edge-functions/supabase/functions/upstash-redis-ratelimit, so start from that rather than writing the counter by hand.
Rate limit in Next.js route handlers
Your Next.js app has its own public surface: route handlers, Server Actions and form posts that call Supabase on the server. Those need limits too, and where you store the counters decides whether the limit works.
Vercel's security review lesson for Next.js lists the options:
- In-memory Map. Simple, but it only works on a single server and resets on restart.
- Redis. A shared store that several servers can use, which fits production.
- A Redis provider from the Vercel Marketplace. Serverless-compatible. The lesson notes that Vercel KV is no longer available for new projects and that existing stores were migrated to Upstash Redis.
On serverless hosting, every request can land on a different instance, so an in-memory Map counts almost nothing. Treat it as a local-development shortcut:
// Single server only. Resets on restart. Use Redis in production.
const hits = new Map<string, { count: number; resetAt: number }>();
export function allow(key: string, limit: number, windowMs: number) {
const now = Date.now();
const entry = hits.get(key);
if (!entry || entry.resetAt <= now) {
hits.set(key, { count: 1, resetAt: now + windowMs });
return true;
}
entry.count += 1;
return entry.count <= limit;
}
That is a fixed window: the counter starts at the first request and resets after the window. It's easy to reason about, but it allows a burst at each boundary. A sliding window is more accurate and more complex, so pick it when bursts at the boundary would hurt.
When a request is over the limit, return 429 with a short error body. Adding a Retry-After header tells well-behaved clients when to come back, and logging the rejection gives you something to monitor. Apply different limits to different routes. The lesson's example figures are 5 requests per minute for auth endpoints, 100 per minute for general API routes and 1,000 per hour for analytics. Treat those as starting points, not rules.
Where you run the check also matters. Keep it in a route handler or Server Action, close to the Supabase call. Our piece on Server and Client Components explains why that code never reaches the browser.
Pick the key: user ID or IP
A limit is only as good as the key you count against. Choose it on purpose.
- Signed in: use the user ID. It follows the person across networks and does not punish a shared office IP.
- Anonymous: use the IP address. It is the only handle you have before sign-in.
Read the IP from x-forwarded-for only after you confirm your hosting layer sets it reliably. Vercel's lesson falls back to the string "unknown" in its demo and presents that as a shortcut, because it puts every unknown client in one bucket. Do not copy that into production.
Endpoints that spend money need the tightest keys. A route that calls a paid model API can turn one abusive client into a bill, so give it a per-user limit and read how to contain prompt injection in AI agents before you expose it.
Add CAPTCHA to sign-up and anonymous sign-ins
Rate limits slow a bot down. They do not tell a bot from a person. For endpoints that anyone can hit, Supabase's anonymous sign-in guide recommends invisible CAPTCHA or Cloudflare Turnstile, because bad actors can abuse the endpoint to increase your database size drastically. The default of 30 anonymous sign-ins per hour per IP is adjustable in the dashboard, so lower it if your app does not need that many.
The same reasoning applies to email sign-up, where each request can send a message. A CAPTCHA in front of the form plus the Auth limits above covers most of the abuse you will see.
Conclusion
Start with what Supabase gives you: review the Auth limits and turn on CAPTCHA for sign-up and anonymous sign-ins. Then protect your own writes with a Postgres pre-request function or a Redis-backed Edge Function, and throttle Next.js route handlers with a shared store. Key on user ID when you can and on a verified IP when you cannot. Test each layer by sending more requests than the limit allows and confirming you get a 429.
If you'd like a second pair of eyes on this setup, our platform and infrastructure work covers Supabase and Next.js backends.
Frequently asked questions
Does Supabase rate limit my app automatically?
Only Auth. Supabase applies default limits to Auth endpoints, such as 30 anonymous sign-ins per hour and 150 token requests per 5 minutes, and returns 429 when you exceed them. Your own Data API writes, Edge Functions and Next.js routes need limits you add yourself.
Can I rate limit GET requests with a Postgres pre-request function?
No. Supabase documents that only POST, PUT, PATCH and DELETE can be limited this way, because GET and HEAD run in read-only mode and may be served by read replicas that cannot write counters.
Is an in-memory counter enough in Next.js?
Only on a single long-lived server. Counters reset on restart and are not shared between instances, so a serverless deployment needs a shared store such as Redis.
Should I key limits on IP or user ID?
Use the user ID for signed-in requests and the IP for anonymous ones. Confirm your proxy sets x-forwarded-for reliably before you trust it.