diff --git a/src/server/routers/chat.ts b/src/server/routers/chat.ts index bdf0127..055aa8f 100644 --- a/src/server/routers/chat.ts +++ b/src/server/routers/chat.ts @@ -9,12 +9,12 @@ import { eq } from 'drizzle-orm'; import { clerkClient, auth } from '@clerk/nextjs/server' export const chatRouter = router({ getSession: publicProcedure.query(async () => { - const clerk = await clerkClient() const { userId } = await auth(); - const user = await clerk.users.getUser(userId?userId:"") - if (user == undefined) { + if (!userId) { throw new TRPCError({ message: "chat is only available to signed in users", code: 'UNAUTHORIZED' }); } + const clerk = await clerkClient() + const user = await clerk.users.getUser(userId) let session = await db.query.chatSession.findFirst({ where(fields, operators) { return operators.eq(fields.userId, user.id)