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'
|
import { clerkClient, auth } from '@clerk/nextjs/server'
|
||||||
export const chatRouter = router({
|
export const chatRouter = router({
|
||||||
getSession: publicProcedure.query(async () => {
|
getSession: publicProcedure.query(async () => {
|
||||||
const clerk = await clerkClient()
|
|
||||||
const { userId } = await auth();
|
const { userId } = await auth();
|
||||||
const user = await clerk.users.getUser(userId?userId:"")
|
if (!userId) {
|
||||||
if (user == undefined) {
|
|
||||||
throw new TRPCError({ message: "chat is only available to signed in users", code: 'UNAUTHORIZED' });
|
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({
|
let session = await db.query.chatSession.findFirst({
|
||||||
where(fields, operators) {
|
where(fields, operators) {
|
||||||
return operators.eq(fields.userId, user.id)
|
return operators.eq(fields.userId, user.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user