Supabase
Learn about the integration between Borrow Limiter and Supabase, and how it can simplify your rate limiting implementation in Supabase Edge Functions.
Supabase Integration
The TS/JS client library for limiter is integrated with Supabase to make your life easier as a developer.
The way it works is if you want to rate limit a user ID, instead of getting the environment variables, creating a Supabase instance, and parsing the authentication token, you can simply pass the request object to the limiter function and we'll handle the rest for you!
You can also pass only the request object to the limiter function and it'll automatically create a unique key for the request based on the request URL.
This might have diminishing returns for when you already need the user object anyway, but for simple use cases where you just want to protect an endpoint and return a response without touching the user object, this greatly simplifies the whole process!
IP address fallback
If the user ID can't be determined, for example, when running outside a Supabase environment or
when the user isn't logged in, Limiter automatically falls back to using the client's IP address
as the user identifier. It checks headers such as X-Forwarded-For, CF-Connecting-IP, and
X-Real-IP.
Here's how it works:
import { limiter } from "@borrowdev/limiter";
async function handler(req: Request) {
const { success, timeLeft } = await limiter(req, {
limiters: [
{
interval: 20,
maxRequests: 10,
type: "fixed",
},
],
});
}
// ... Your expensive business logic