aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc
diff options
context:
space:
mode:
Diffstat (limited to 'packages/trpc')
-rw-r--r--packages/trpc/index.ts2
-rw-r--r--packages/trpc/routers/users.ts18
2 files changed, 19 insertions, 1 deletions
diff --git a/packages/trpc/index.ts b/packages/trpc/index.ts
index a32eb871..6ca0bbf7 100644
--- a/packages/trpc/index.ts
+++ b/packages/trpc/index.ts
@@ -5,6 +5,8 @@ import superjson from "superjson";
type User = {
id: string;
+ name: string;
+ email: string;
role: "admin" | "user" | null;
};
diff --git a/packages/trpc/routers/users.ts b/packages/trpc/routers/users.ts
index b5334f99..efef61af 100644
--- a/packages/trpc/routers/users.ts
+++ b/packages/trpc/routers/users.ts
@@ -1,5 +1,10 @@
import { zSignUpSchema } from "../types/users";
-import { adminProcedure, publicProcedure, router } from "../index";
+import {
+ adminProcedure,
+ authedProcedure,
+ publicProcedure,
+ router,
+} from "../index";
import { SqliteError } from "@hoarder/db";
import { z } from "zod";
import { hashPassword } from "../auth";
@@ -90,4 +95,15 @@ export const usersAppRouter = router({
throw new TRPCError({ code: "NOT_FOUND" });
}
}),
+ whoami: authedProcedure
+ .output(
+ z.object({
+ id: z.string(),
+ name: z.string(),
+ email: z.string(),
+ }),
+ )
+ .query(async ({ ctx }) => {
+ return { id: ctx.user.id, name: ctx.user.name, email: ctx.user.email };
+ }),
});