aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workers/trpc.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2024-11-03 17:09:47 +0000
committerMohamed Bassem <me@mbassem.com>2024-11-03 17:09:47 +0000
commitcf1a25131fd45ab7c9a72b837be525c24457cd8b (patch)
treecb8b3d4a57a4ce06e500e4c7ceea43924d64a5d4 /apps/workers/trpc.ts
parent2efc7c8c01866fafad5322fb8783d94821e32ff1 (diff)
downloadkarakeep-cf1a25131fd45ab7c9a72b837be525c24457cd8b.tar.zst
feature: Add support for subscribing to RSS feeds. Fixes #202
Diffstat (limited to 'apps/workers/trpc.ts')
-rw-r--r--apps/workers/trpc.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/apps/workers/trpc.ts b/apps/workers/trpc.ts
new file mode 100644
index 00000000..cd2e4c99
--- /dev/null
+++ b/apps/workers/trpc.ts
@@ -0,0 +1,33 @@
+import { eq } from "drizzle-orm";
+
+import { db } from "@hoarder/db";
+import { users } from "@hoarder/db/schema";
+import { createCallerFactory } from "@hoarder/trpc";
+import { appRouter } from "@hoarder/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);
+
+ const user = await db.query.users.findFirst({
+ where: eq(users.id, userId),
+ });
+ if (!user) {
+ throw new Error("User not found");
+ }
+
+ return createCaller({
+ user: {
+ id: user.id,
+ name: user.name,
+ email: user.email,
+ role: user.role,
+ },
+ db,
+ req: {
+ ip: null,
+ },
+ });
+}