@@ -39,6 +39,8 @@ export async function authorizeCredentialUse(
3939 return { ok : false , error : auth . error || 'Authentication required' }
4040 }
4141
42+ const actingUserId = auth . authType === 'internal_jwt' ? callerUserId : auth . userId
43+
4244 const [ workflowContext ] = workflowId
4345 ? await db
4446 . select ( { workspaceId : workflowTable . workspaceId } )
@@ -81,12 +83,9 @@ export async function authorizeCredentialUse(
8183 return { ok : false , error : 'Credential account not found' }
8284 }
8385
84- const effectiveCallerId =
85- callerUserId || ( auth . authType !== 'internal_jwt' ? auth . userId : null )
86-
87- if ( effectiveCallerId ) {
86+ if ( actingUserId ) {
8887 const requesterPerm = await getUserEntityPermissions (
89- effectiveCallerId ,
88+ actingUserId ,
9089 'workspace' ,
9190 platformCredential . workspaceId
9291 )
@@ -97,7 +96,7 @@ export async function authorizeCredentialUse(
9796 . where (
9897 and (
9998 eq ( credentialMember . credentialId , platformCredential . id ) ,
100- eq ( credentialMember . userId , effectiveCallerId ) ,
99+ eq ( credentialMember . userId , actingUserId ) ,
101100 eq ( credentialMember . status , 'active' )
102101 )
103102 )
@@ -167,16 +166,14 @@ export async function authorizeCredentialUse(
167166 return { ok : false , error : 'Credential account not found' }
168167 }
169168
170- const legacyCallerId = callerUserId || ( auth . authType !== 'internal_jwt' ? auth . userId : null )
171-
172- if ( legacyCallerId ) {
169+ if ( actingUserId ) {
173170 const [ membership ] = await db
174171 . select ( { id : credentialMember . id } )
175172 . from ( credentialMember )
176173 . where (
177174 and (
178175 eq ( credentialMember . credentialId , workspaceCredential . id ) ,
179- eq ( credentialMember . userId , legacyCallerId ) ,
176+ eq ( credentialMember . userId , actingUserId ) ,
180177 eq ( credentialMember . status , 'active' )
181178 )
182179 )
0 commit comments