kinsyu
kinsyu2y ago

tRPC Middleware consuming memory limit on Vercel

Hi all, I'm running into a weird error where my tRPC middleware to enforce that a user is authed, is reaching the memory limit on the request. I've used tRPC with the exact same middleware before and never ran into any of these issues, here's what the middleware looks like:
/** Reusable middleware that enforces users are logged in before running the procedure. */
const enforceUserIsAuthed = t.middleware(({ ctx, next }) => {
try {
console.log("enforceUserIsAuthed");
console.log({ ctx });
} catch (e) {
console.log({ e });
}
if (!ctx.session || !ctx.session.user) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
return next({
ctx: {
// infers the `session` as non-nullable
session: { ...ctx.session, user: ctx.session.user },
},
});
});

/**
* Protected (authenticated) procedure
*
* If you want a query or mutation to ONLY be accessible to logged in users, use this. It verifies
* the session is valid and guarantees `ctx.session.user` is not null.
*
* @see https://trpc.io/docs/procedures
*/
export const protectedProcedure = t.procedure.use(enforceUserIsAuthed);
/** Reusable middleware that enforces users are logged in before running the procedure. */
const enforceUserIsAuthed = t.middleware(({ ctx, next }) => {
try {
console.log("enforceUserIsAuthed");
console.log({ ctx });
} catch (e) {
console.log({ e });
}
if (!ctx.session || !ctx.session.user) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
return next({
ctx: {
// infers the `session` as non-nullable
session: { ...ctx.session, user: ctx.session.user },
},
});
});

/**
* Protected (authenticated) procedure
*
* If you want a query or mutation to ONLY be accessible to logged in users, use this. It verifies
* the session is valid and guarantees `ctx.session.user` is not null.
*
* @see https://trpc.io/docs/procedures
*/
export const protectedProcedure = t.procedure.use(enforceUserIsAuthed);
And here's the request in Vercel's logs.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?