Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions apps/sim/app/api/copilot/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { and, desc, eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { getSession } from '@/lib/auth'
import {
authenticateCopilotRequestSessionOnly,
createBadRequestResponse,
Expand Down Expand Up @@ -125,14 +126,15 @@ export async function POST(req: NextRequest) {
const tracker = createRequestTracker()

try {
// Authenticate user using consolidated helper
const { userId: authenticatedUserId, isAuthenticated } =
await authenticateCopilotRequestSessionOnly()
// Get session to access user information including name
const session = await getSession()

if (!isAuthenticated || !authenticatedUserId) {
if (!session?.user?.id) {
return createUnauthorizedResponse()
}

const authenticatedUserId = session.user.id

const body = await req.json()
const {
message,
Expand Down Expand Up @@ -242,6 +244,7 @@ export async function POST(req: NextRequest) {
stream: stream,
streamToolCalls: true,
mode: mode,
...(createNewChat && session?.user?.name && { userName: session.user.name }),
}),
})

Expand Down