@@ -4,7 +4,7 @@ import { createLogger } from '@sim/logger'
44import { and , desc , eq , isNull , or } from 'drizzle-orm'
55import { type NextRequest , NextResponse } from 'next/server'
66import { z } from 'zod'
7- import { checkHybridAuth } from '@/lib/auth/hybrid'
7+ import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
88import { generateRequestId } from '@/lib/core/utils/request'
99import { upsertCustomTools } from '@/lib/workflows/custom-tools/operations'
1010import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
@@ -42,8 +42,8 @@ export async function GET(request: NextRequest) {
4242 const workflowId = searchParams . get ( 'workflowId' )
4343
4444 try {
45- // Use hybrid auth to support session, API key, and internal JWT
46- const authResult = await checkHybridAuth ( request , { requireWorkflowId : false } )
45+ // Use session/internal auth to support session and internal JWT (no API key access)
46+ const authResult = await checkSessionOrInternalAuth ( request , { requireWorkflowId : false } )
4747 if ( ! authResult . success || ! authResult . userId ) {
4848 logger . warn ( `[${ requestId } ] Unauthorized custom tools access attempt` )
4949 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } )
@@ -69,8 +69,8 @@ export async function GET(request: NextRequest) {
6969 }
7070
7171 // Check workspace permissions
72- // For internal JWT with workflowId: checkHybridAuth already resolved userId from workflow owner
73- // For session/API key : verify user has access to the workspace
72+ // For internal JWT with workflowId: checkSessionOrInternalAuth already resolved userId from workflow owner
73+ // For session: verify user has access to the workspace
7474 // For legacy (no workspaceId): skip workspace check, rely on userId match
7575 if ( resolvedWorkspaceId && ! ( authResult . authType === 'internal_jwt' && workflowId ) ) {
7676 const userPermission = await getUserEntityPermissions (
@@ -116,8 +116,8 @@ export async function POST(req: NextRequest) {
116116 const requestId = generateRequestId ( )
117117
118118 try {
119- // Use hybrid auth (though this endpoint is only called from UI )
120- const authResult = await checkHybridAuth ( req , { requireWorkflowId : false } )
119+ // Use session/internal auth (no API key access )
120+ const authResult = await checkSessionOrInternalAuth ( req , { requireWorkflowId : false } )
121121 if ( ! authResult . success || ! authResult . userId ) {
122122 logger . warn ( `[${ requestId } ] Unauthorized custom tools update attempt` )
123123 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } )
@@ -193,8 +193,8 @@ export async function DELETE(request: NextRequest) {
193193 }
194194
195195 try {
196- // Use hybrid auth (though this endpoint is only called from UI )
197- const authResult = await checkHybridAuth ( request , { requireWorkflowId : false } )
196+ // Use session/internal auth (no API key access )
197+ const authResult = await checkSessionOrInternalAuth ( request , { requireWorkflowId : false } )
198198 if ( ! authResult . success || ! authResult . userId ) {
199199 logger . warn ( `[${ requestId } ] Unauthorized custom tool deletion attempt` )
200200 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } )
0 commit comments