Skip to content

Commit 0ce6e4f

Browse files
author
waleed
committed
resolve merge conflicts
1 parent fad5e85 commit 0ce6e4f

2 files changed

Lines changed: 17 additions & 38 deletions

File tree

apps/sim/app/api/chat/utils.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,7 @@ import { type NextRequest, NextResponse } from 'next/server'
55
import { isDev } from '@/lib/environment'
66
import { createLogger } from '@/lib/logs/console/logger'
77
import { hasAdminPermission } from '@/lib/permissions/utils'
8-
import { processStreamingBlockLogs } from '@/lib/tokenization'
9-
import { decryptSecret, generateRequestId } from '@/lib/utils'
10-
import { TriggerUtils } from '@/lib/workflows/triggers'
11-
import { CHAT_ERROR_MESSAGES } from '@/app/chat/constants'
12-
import { getBlock } from '@/blocks'
13-
import { Executor } from '@/executor'
14-
import type { BlockLog, ExecutionResult, StreamingExecution } from '@/executor/types'
15-
import { Serializer } from '@/serializer'
16-
import { mergeSubblockState } from '@/stores/workflows/server-utils'
17-
import type { WorkflowState } from '@/stores/workflows/workflow/types'
18-
19-
declare global {
20-
var __chatStreamProcessingTasks: Promise<{ success: boolean; error?: any }>[] | undefined
21-
}
8+
import { decryptSecret } from '@/lib/utils'
229

2310
const logger = createLogger('ChatAuthUtils')
2411

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function resolveOutputIds(
122122
export async function executeWorkflow(
123123
workflow: any,
124124
requestId: string,
125-
input?: any,
125+
input: any | undefined,
126126
actorUserId: string,
127127
streamConfig?: {
128128
enabled: boolean
@@ -638,37 +638,29 @@ export async function POST(
638638
let authenticatedUserId: string
639639
let triggerType: TriggerType = 'manual'
640640

641-
const session = await getSession()
642-
const apiKeyHeader = request.headers.get('X-API-Key')
643-
if (session?.user?.id && !apiKeyHeader) {
644-
authenticatedUserId = session.user.id
645-
triggerType = 'manual'
646-
} else if (apiKeyHeader) {
647-
const auth = await authenticateApiKeyFromHeader(apiKeyHeader)
648-
if (!auth.success || !auth.userId) {
649-
return createErrorResponse('Unauthorized', 401)
650-
}
651-
authenticatedUserId = auth.userId
652-
triggerType = 'api'
653-
if (auth.keyId) {
654-
void updateApiKeyLastUsed(auth.keyId).catch(() => {})
655641
// For internal calls (chat deployments), use the workflow owner's ID
656642
if (finalIsSecureMode) {
657643
authenticatedUserId = validation.workflow.userId
658644
triggerType = 'manual' // Chat deployments use manual trigger type (no rate limit)
659645
} else {
660646
const session = await getSession()
661-
if (session?.user?.id) {
647+
const apiKeyHeader = request.headers.get('X-API-Key')
648+
649+
if (session?.user?.id && !apiKeyHeader) {
662650
authenticatedUserId = session.user.id
663-
triggerType = 'manual' // UI session (not rate limited)
664-
} else {
665-
const apiKeyHeader = request.headers.get('X-API-Key')
666-
if (apiKeyHeader) {
667-
authenticatedUserId = validation.workflow.userId
668-
triggerType = 'api'
669-
} else {
670-
return createErrorResponse('Authentication required', 401)
651+
triggerType = 'manual'
652+
} else if (apiKeyHeader) {
653+
const auth = await authenticateApiKeyFromHeader(apiKeyHeader)
654+
if (!auth.success || !auth.userId) {
655+
return createErrorResponse('Unauthorized', 401)
656+
}
657+
authenticatedUserId = auth.userId
658+
triggerType = 'api'
659+
if (auth.keyId) {
660+
void updateApiKeyLastUsed(auth.keyId).catch(() => {})
671661
}
662+
} else {
663+
return createErrorResponse('Authentication required', 401)
672664
}
673665
}
674666

0 commit comments

Comments
 (0)