For plans that introduce a rate limit (e.g. allowing a user to upload 50 files per month), it’s recommended to limit the number of API calls a user can perform in a given time frame based on their IP address. In this example, we’ll be limiting it to 5 API calls per minute using Upstash.
middleware.ts
file should look like at the end of this
page.UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
.
.env.local
in the codebase:
supabaseClient.auth.getUser()
function. Otherwise, the rate limit will not work as it will be
executed after all the API calls have been made.