aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/index.ts
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-03-30 16:26:16 +0000
committerMohamedBassem <me@mbassem.com>2024-03-30 16:26:16 +0000
commit46b78eaac30be26fe40520e97786563344af8403 (patch)
treec4c0e1ae1d3d21a6f1fbf5f44f68e99243bbb5d3 /packages/trpc/index.ts
parent853ed13450b3a0d92cba144cc0dfd0696e7c810c (diff)
downloadkarakeep-46b78eaac30be26fe40520e97786563344af8403.tar.zst
format: Add missing lint and format, and format the entire repo
Diffstat (limited to 'packages/trpc/index.ts')
-rw-r--r--packages/trpc/index.ts19
1 files changed, 10 insertions, 9 deletions
diff --git a/packages/trpc/index.ts b/packages/trpc/index.ts
index 51c713c0..4055fa5d 100644
--- a/packages/trpc/index.ts
+++ b/packages/trpc/index.ts
@@ -1,20 +1,21 @@
-import { db } from "@hoarder/db";
-import serverConfig from "@hoarder/shared/config";
-import { TRPCError, initTRPC } from "@trpc/server";
+import { initTRPC, TRPCError } from "@trpc/server";
import superjson from "superjson";
import { ZodError } from "zod";
-type User = {
+import type { db } from "@hoarder/db";
+import serverConfig from "@hoarder/shared/config";
+
+interface User {
id: string;
name?: string | null | undefined;
email?: string | null | undefined;
role: "admin" | "user" | null;
-};
+}
-export type Context = {
+export interface Context {
user: User | null;
db: typeof db;
-};
+}
// Avoid exporting the entire t-object
// since it's not very descriptive.
@@ -29,7 +30,7 @@ const t = initTRPC.context<Context>().create({
data: {
...shape.data,
zodError:
- error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
+ error.code === "BAD_REQUEST" && error.cause instanceof ZodError
? error.cause.flatten()
: null,
},
@@ -53,7 +54,7 @@ export const publicProcedure = procedure;
export const authedProcedure = procedure.use(function isAuthed(opts) {
const user = opts.ctx.user;
- if (!user || !user.id) {
+ if (!user?.id) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}