* trpc procedures an middleware refactor * allow use sessionMiddleware without a req object * sync with the new tRPC structure * tRPC refactor on routing form app * import Prisma from @prisma/client * Lazy load apps from appstore * remove unrelated changes * Add types for PaymentService * type fixes * Merge branch 'main' into roae85/cal-1514-set-the-user-session-only-on-the * fix typo * remove console.log * remove explicit types from apstore object * linter fixes --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import perfMiddleware from "../middlewares/perfMiddleware";
|
|
import { isAdminMiddleware, isAuthed } from "../middlewares/sessionMiddleware";
|
|
import { procedure } from "../trpc";
|
|
import publicProcedure from "./publicProcedure";
|
|
|
|
/*interface IRateLimitOptions {
|
|
intervalInMs: number;
|
|
limit: number;
|
|
}
|
|
const isRateLimitedByUserIdMiddleware = ({ intervalInMs, limit }: IRateLimitOptions) =>
|
|
middleware(({ ctx, next }) => {
|
|
// validate user exists
|
|
if (!ctx.user) {
|
|
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
}
|
|
|
|
const { isRateLimited } = rateLimit({ intervalInMs }).check(limit, ctx.user.id.toString());
|
|
|
|
if (isRateLimited) {
|
|
throw new TRPCError({ code: "TOO_MANY_REQUESTS" });
|
|
}
|
|
|
|
return next({ ctx: { user: ctx.user, session: ctx.session } });
|
|
});
|
|
*/
|
|
const authedProcedure = procedure.use(perfMiddleware).use(isAuthed);
|
|
/*export const authedRateLimitedProcedure = ({ intervalInMs, limit }: IRateLimitOptions) =>
|
|
authedProcedure.use(isRateLimitedByUserIdMiddleware({ intervalInMs, limit }));*/
|
|
export const authedAdminProcedure = publicProcedure.use(isAdminMiddleware);
|
|
|
|
export default authedProcedure;
|