Rate Limiting in a SvelteKit app
I'm on the verge of completing a project (with SSR) for a client and want some guidance on how to prevent the entire app (not just a few sections) from being bombarded with requests. Bear in mind this is my first time building something like this, since I've been very front-end focused, so please be kind 😅.
Here's my tech stack: SvelteKit, Bun, Supabase, Fly.io .
I'm looking at the Better Auth Rate Limit guide but I'm not sure if it's possible to use Better Auth just for the rate limit aspect, since I'm using Supabase Auth.
Ideally, I'd like a check to happen as early as possible, for example, in the
hooks.server.ts
file.
I appreciate any help you can provide.3 Replies
Heya fellow Frontend Friend 😂 I'm also just starting with SvelteKit, so also fairly little Backend experience. While I am not sure what exactly better-auth's rate limiter is capable of, I have found a library which probably does cover your needs.
Check out the npm package
sveltekit-rate-limiter
. Once you configured a rate limiter you can use it in the hooke.server.ts
file as the first handler. Perhaps this can help you further!Definitely helps, thank you very much! Someone else suggested this to me on Reddit earlier. Should’ve updated this thread. My bad.
Ah no worries, glad you found some help 😁