diff --git a/server/src/trpc.ts b/server/src/trpc.ts index ef9e8a20a..dc04f942d 100644 --- a/server/src/trpc.ts +++ b/server/src/trpc.ts @@ -2,7 +2,7 @@ import { TRPCError, initTRPC } from '@trpc/server'; import type * as trpcExpress from '@trpc/server/adapters/express'; import { getUserByTokenService } from './services/user/getUserByToken'; -const t = initTRPC.create(); +const t = initTRPC.context().create(); /** * Create a context object that will be passed to all resolvers @@ -42,7 +42,7 @@ export const createContext = async ({ }; }; -export type Context = inferAsyncReturnType; +export type Context = Awaited>; /** * Export reusable router and procedure helpers @@ -65,7 +65,7 @@ const isAuthenticated = t.middleware(async (opts) => { message: 'Invalid token', }); } - return next(ctx); + return next({ ctx: { ...ctx, user: ctx.user } }); }); export const protectedProcedure = t.procedure.use(isAuthenticated);