diff options
Diffstat (limited to 'apps/workers/trpc.ts')
| -rw-r--r-- | apps/workers/trpc.ts | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/apps/workers/trpc.ts b/apps/workers/trpc.ts index 8bae287a..c5f880ad 100644 --- a/apps/workers/trpc.ts +++ b/apps/workers/trpc.ts @@ -2,15 +2,15 @@ import { eq } from "drizzle-orm"; import { db } from "@karakeep/db"; import { users } from "@karakeep/db/schema"; -import { createCallerFactory } from "@karakeep/trpc"; +import { AuthedContext, createCallerFactory } from "@karakeep/trpc"; import { appRouter } from "@karakeep/trpc/routers/_app"; /** * This is only safe to use in the context of a worker. */ -export async function buildImpersonatingTRPCClient(userId: string) { - const createCaller = createCallerFactory(appRouter); - +export async function buildImpersonatingAuthedContext( + userId: string, +): Promise<AuthedContext> { const user = await db.query.users.findFirst({ where: eq(users.id, userId), }); @@ -18,7 +18,7 @@ export async function buildImpersonatingTRPCClient(userId: string) { throw new Error("User not found"); } - return createCaller({ + return { user: { id: user.id, name: user.name, @@ -29,5 +29,14 @@ export async function buildImpersonatingTRPCClient(userId: string) { req: { ip: null, }, - }); + }; +} + +/** + * This is only safe to use in the context of a worker. + */ +export async function buildImpersonatingTRPCClient(userId: string) { + const createCaller = createCallerFactory(appRouter); + + return createCaller(await buildImpersonatingAuthedContext(userId)); } |
