chat interface, validate user id

This commit is contained in:
2026-04-24 12:11:29 +02:00
parent 538d896b0e
commit da43b31aa3

View File

@@ -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)