Next.js Discord

Discord Forum

How can I implement rate limiting with NextAuth in Next.js 13 (app router)?

Unanswered
TheOrphan posted this in #help-forum
Open in Discord
Any ideas? I've seen many tutorials on implementing rate limiting using the page router in Next.js. However, I'm struggling to find resources for implementing it with the app router, especially when combined with NextAuth. Does anyone have any guidance or resources on this?

3 Replies

you can use @upstash/ratelimit. both Upstash and Vercel have blog posts showing how to do this
True, but doesn't using @upstash/ratelimit require me to register and maintain a database with Upstash? In my use case, I have my own backend and database. I also plan to mask and secure my Java backend, so ideally, I'd like the rate limiter to function from Next.js itself without having to communicate with my Java backend. Furthermore, I'll be implementing this for our office environment where the infrastructure has to be in-house. Our deployment strategy also mandates the use of our own servers. Basically, my intention is to prevent the need to set up and maintain a new database and backend outside our current ecosystem.