diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-05 16:30:31 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-05 16:30:44 +0000 |
| commit | 56c5236245359987e7a729979de3892bbee70852 (patch) | |
| tree | d5acb844b606502263414eff030c3c5708f6e98b /packages/trpc | |
| parent | 9490a3a616f526ee7b495abab27af111df16bbb4 (diff) | |
| download | karakeep-56c5236245359987e7a729979de3892bbee70852.tar.zst | |
extension: Show who the logged in user is in the extension options
Diffstat (limited to 'packages/trpc')
| -rw-r--r-- | packages/trpc/index.ts | 2 | ||||
| -rw-r--r-- | packages/trpc/routers/users.ts | 18 |
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 }; + }), }); |
