@@ -6,7 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server'
66import { z } from 'zod'
77import { getAuditActorMetadata } from '@/lib/audit/actor-metadata'
88import { AuditAction , AuditResourceType , recordAudit } from '@/lib/audit/log'
9- import { AuthType , checkHybridAuth } from '@/lib/auth/hybrid'
9+ import { checkHybridAuth } from '@/lib/auth/hybrid'
1010import { generateRequestId } from '@/lib/core/utils/request'
1111import { archiveWorkflow } from '@/lib/workflows/lifecycle'
1212import { loadWorkflowFromNormalizedTables } from '@/lib/workflows/persistence/utils'
@@ -40,7 +40,6 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
4040 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } )
4141 }
4242
43- const isInternalCall = auth . authType === AuthType . INTERNAL_JWT
4443 const userId = auth . userId || null
4544
4645 let workflowData = await getWorkflowById ( workflowId )
@@ -54,32 +53,28 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
5453 return NextResponse . json ( { error : 'Workflow not found' } , { status : 404 } )
5554 }
5655
57- if ( isInternalCall && ! userId ) {
58- // Internal system calls (e.g. workflow-in-workflow executor) may not carry a userId.
59- // These are already authenticated via internal JWT; allow read access.
60- logger . info ( `[${ requestId } ] Internal API call for workflow ${ workflowId } ` )
61- } else if ( ! userId ) {
56+ if ( ! userId ) {
6257 logger . warn ( `[${ requestId } ] Unauthorized access attempt for workflow ${ workflowId } ` )
6358 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } )
64- } else {
65- const authorization = await authorizeWorkflowByWorkspacePermission ( {
66- workflowId,
67- userId,
68- action : 'read' ,
69- } )
70- if ( ! authorization . workflow ) {
71- logger . warn ( `[${ requestId } ] Workflow ${ workflowId } not found` )
72- return NextResponse . json ( { error : 'Workflow not found' } , { status : 404 } )
73- }
59+ }
7460
75- workflowData = authorization . workflow
76- if ( ! authorization . allowed ) {
77- logger . warn ( `[${ requestId } ] User ${ userId } denied access to workflow ${ workflowId } ` )
78- return NextResponse . json (
79- { error : authorization . message || 'Access denied' } ,
80- { status : authorization . status }
81- )
82- }
61+ const authorization = await authorizeWorkflowByWorkspacePermission ( {
62+ workflowId,
63+ userId,
64+ action : 'read' ,
65+ } )
66+ if ( ! authorization . workflow ) {
67+ logger . warn ( `[${ requestId } ] Workflow ${ workflowId } not found` )
68+ return NextResponse . json ( { error : 'Workflow not found' } , { status : 404 } )
69+ }
70+
71+ workflowData = authorization . workflow
72+ if ( ! authorization . allowed ) {
73+ logger . warn ( `[${ requestId } ] User ${ userId } denied access to workflow ${ workflowId } ` )
74+ return NextResponse . json (
75+ { error : authorization . message || 'Access denied' } ,
76+ { status : authorization . status }
77+ )
8378 }
8479
8580 const normalizedData = await loadWorkflowFromNormalizedTables ( workflowId )
0 commit comments