@@ -420,31 +420,33 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
420420
421421 /**
422422 * Subscription handlers, pollers, and subscription cleanup look `credentialId`
423- * up by id alone and mint tokens as its owner. A save acts with the requested
424- * credential or, when the request omits it, the stored one, so that credential
425- * must be usable by the actor in the workflow's workspace before anything is
426- * subscribed, cleaned up, or saved.
423+ * up by id alone and mint tokens as its owner. A save can act with both the
424+ * requested credential and the stored one — the stored one is merged back when
425+ * the request omits it, or used to clean up the previous subscription — so
426+ * each must be usable by the actor in the workflow's workspace before anything
427+ * is subscribed, cleaned up, or saved.
427428 */
428- const effectiveCredentialId =
429- 'credentialId' in originalProviderConfig
430- ? originalProviderConfig . credentialId
431- : existingWebhook ?. providerConfig ?. credentialId
432- if ( effectiveCredentialId != null && effectiveCredentialId !== '' ) {
433- if ( typeof effectiveCredentialId !== 'string' ) {
429+ const credentialIds = new Set (
430+ [ originalProviderConfig . credentialId , existingWebhook ?. providerConfig ?. credentialId ] . filter (
431+ ( id ) => id != null && id !== ''
432+ )
433+ )
434+ for ( const credentialId of credentialIds ) {
435+ if ( typeof credentialId !== 'string' ) {
434436 return NextResponse . json (
435437 { error : 'providerConfig.credentialId must be a literal credential id' } ,
436438 { status : 400 }
437439 )
438440 }
439441 const credentialAccess = await authorizeCredentialUseForAuth (
440442 { success : true , userId, authType : AuthType . SESSION } ,
441- { credentialId : effectiveCredentialId , workflowId }
443+ { credentialId, workflowId }
442444 )
443445 if ( ! credentialAccess . ok ) {
444446 logger . warn ( `[${ requestId } ] Webhook credential reference denied` , {
445447 userId,
446448 workflowId,
447- credentialId : effectiveCredentialId ,
449+ credentialId,
448450 reason : credentialAccess . error ,
449451 } )
450452 return NextResponse . json ( { error : credentialAccess . error } , { status : 403 } )
0 commit comments