diff options
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/trpc/routers/users.ts | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/packages/trpc/routers/users.ts b/packages/trpc/routers/users.ts index 51f9429e..ba1aee24 100644 --- a/packages/trpc/routers/users.ts +++ b/packages/trpc/routers/users.ts @@ -1,5 +1,5 @@ import { TRPCError } from "@trpc/server"; -import { count, eq } from "drizzle-orm"; +import { and, count, eq } from "drizzle-orm"; import invariant from "tiny-invariant"; import { z } from "zod"; @@ -138,7 +138,16 @@ export const usersAppRouter = router({ email: z.string().nullish(), }), ) - .query(({ ctx }) => { + .query(async ({ ctx }) => { + if (!ctx.user.email) { + throw new TRPCError({ code: "UNAUTHORIZED" }); + } + const userDb = await ctx.db.query.users.findFirst({ + where: and(eq(users.id, ctx.user.id), eq(users.email, ctx.user.email)), + }); + if (!userDb) { + throw new TRPCError({ code: "UNAUTHORIZED" }); + } return { id: ctx.user.id, name: ctx.user.name, email: ctx.user.email }; }), }); |
