* feat: install rate-limiter-flexible and ioredis * feat: setup redis client * feat: add withRateLimit wrapper * feat: wrap trpc endpoint in withRateLimit * feat: wrap withRateLimit on remaining routes * feat: exclude webhook route from rate limiting * chore: update compose files and readme * refactor: move into api/db packages
19 lines
503 B
TypeScript
19 lines
503 B
TypeScript
import { toNodeHandler } from "better-auth/node";
|
|
|
|
import { initAuth } from "@kan/auth/server";
|
|
import { createDrizzleClient } from "@kan/db/client";
|
|
import { withRateLimit } from "@kan/api/utils/rateLimit";
|
|
|
|
export const config = { api: { bodyParser: false } };
|
|
|
|
export const auth = initAuth(createDrizzleClient());
|
|
|
|
const authHandler = toNodeHandler(auth.handler);
|
|
|
|
export default withRateLimit(
|
|
{ points: 100, duration: 60 },
|
|
async (req, res) => {
|
|
return await authHandler(req, res);
|
|
},
|
|
);
|