@@ -38,6 +38,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
3838 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } )
3939 }
4040
41+ const isInternalCall = auth . authType === 'internal_jwt'
4142 const userId = auth . userId || null
4243
4344 let workflowData = await getWorkflowById ( workflowId )
@@ -47,29 +48,32 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
4748 return NextResponse . json ( { error : 'Workflow not found' } , { status : 404 } )
4849 }
4950
50- // Check if user has access to this workflow
51- if ( ! userId ) {
51+ if ( isInternalCall && ! userId ) {
52+ // Internal system calls (e.g. workflow-in-workflow executor) may not carry a userId.
53+ // These are already authenticated via internal JWT; allow read access.
54+ logger . info ( `[${ requestId } ] Internal API call for workflow ${ workflowId } ` )
55+ } else if ( ! userId ) {
5256 logger . warn ( `[${ requestId } ] Unauthorized access attempt for workflow ${ workflowId } ` )
5357 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } )
54- }
55-
56- const authorization = await authorizeWorkflowByWorkspacePermission ( {
57- workflowId,
58- userId,
59- action : 'read' ,
60- } )
61- if ( ! authorization . workflow ) {
62- logger . warn ( `[${ requestId } ] Workflow ${ workflowId } not found` )
63- return NextResponse . json ( { error : 'Workflow not found' } , { status : 404 } )
64- }
58+ } else {
59+ const authorization = await authorizeWorkflowByWorkspacePermission ( {
60+ workflowId,
61+ userId,
62+ action : 'read' ,
63+ } )
64+ if ( ! authorization . workflow ) {
65+ logger . warn ( `[${ requestId } ] Workflow ${ workflowId } not found` )
66+ return NextResponse . json ( { error : 'Workflow not found' } , { status : 404 } )
67+ }
6568
66- workflowData = authorization . workflow
67- if ( ! authorization . allowed ) {
68- logger . warn ( `[${ requestId } ] User ${ userId } denied access to workflow ${ workflowId } ` )
69- return NextResponse . json (
70- { error : authorization . message || 'Access denied' } ,
71- { status : authorization . status }
72- )
69+ workflowData = authorization . workflow
70+ if ( ! authorization . allowed ) {
71+ logger . warn ( `[${ requestId } ] User ${ userId } denied access to workflow ${ workflowId } ` )
72+ return NextResponse . json (
73+ { error : authorization . message || 'Access denied' } ,
74+ { status : authorization . status }
75+ )
76+ }
7377 }
7478
7579 logger . debug ( `[${ requestId } ] Attempting to load workflow ${ workflowId } from normalized tables` )
0 commit comments