Upstash Rate Limiter
Use Upstash Redis with Better Auth rateLimit via a wrapper (not a plugin)
Use Upstash Redis in Better Auth.
This is not a traditional Better Auth plugin.
You do not add it to plugins: [].
It is a rateLimit wrapper your for Better Auth config.
Installation
Install dependencies
Coming soon: npm package installation is not published yet.
npm install @better-auth-plugins/plugins @upstash/redisCreate your Redis client
import { Redis } from "@upstash/redis";
export const redis = new Redis({
url: process.env.UPSTASH_REDIS_REST_URL!,
token: process.env.UPSTASH_REDIS_REST_TOKEN!,
});or
import { Redis } from "@upstash/redis";
export const redis = new Redis.fromEnv()Add upstashRateLimiter to rateLimit
import { betterAuth } from "better-auth";
import { upstashRateLimiter } from "@better-auth-plugins/plugins/upstash";
import { redis } from "./lib/redis";
export const auth = betterAuth({
rateLimit: upstashRateLimiter({
redis,
window: 10,
max: 100,
}),
});Better Auth options still work
upstashRateLimiter passes Better Auth rate-limit options through, while injecting custom storage.
That means things like enabled, window, max, customRules, and advanced behavior are still handled by Better Auth.
export const auth = betterAuth({
rateLimit: upstashRateLimiter({
redis,
window: 10,
max: 100,
customRules: {
"/sign-in/email": {
window: 10,
max: 3,
},
"/two-factor/*": async (request) => {
return {
window: 10,
max: 3,
};
},
},
}),
});API
upstashRateLimiter(options)createUpstashRateLimitStorage(options)
options
redis: { get(key), set(key, value, { ex }) }(required)- All Better Auth
rateLimitoptions exceptcustomStorageandstorage