chat interface, validate user id
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user