@@ -3,6 +3,7 @@ import { convertTextToSpeechStream } from 'flowise-components'
33import { StatusCodes } from 'http-status-codes'
44import { InternalFlowiseError } from '../../errors/internalFlowiseError'
55import chatflowsService from '../../services/chatflows'
6+ import credentialsService from '../../services/credentials'
67import textToSpeechService from '../../services/text-to-speech'
78import { databaseEntities } from '../../utils'
89import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
@@ -56,6 +57,17 @@ const generateTextToSpeech = async (req: Request, res: Response) => {
5657 voice = providerConfig . voice
5758 model = providerConfig . model
5859 } else {
60+ // Body-supplied credentials require the caller to be authenticated
61+ const workspaceId = req . user ?. activeWorkspaceId
62+ if ( ! workspaceId ) {
63+ return res . status ( StatusCodes . UNAUTHORIZED ) . json ( { message : 'Authentication required' } )
64+ }
65+ if ( ! bodyCredentialId ) {
66+ return res . status ( StatusCodes . BAD_REQUEST ) . json ( { message : 'credentialId not provided' } )
67+ }
68+ // Verify the credential belongs to the authenticated user's workspace —
69+ // throws NOT_FOUND if the credential doesn't exist or belongs to another workspace
70+ await credentialsService . getCredentialById ( bodyCredentialId , workspaceId )
5971 // Use TTS config from request body
6072 provider = bodyProvider
6173 credentialId = bodyCredentialId
@@ -80,8 +92,6 @@ const generateTextToSpeech = async (req: Request, res: Response) => {
8092 res . setHeader ( 'Content-Type' , 'text/event-stream' )
8193 res . setHeader ( 'Cache-Control' , 'no-cache' )
8294 res . setHeader ( 'Connection' , 'keep-alive' )
83- res . setHeader ( 'Access-Control-Allow-Origin' , '*' )
84- res . setHeader ( 'Access-Control-Allow-Headers' , 'Cache-Control' )
8595
8696 const appServer = getRunningExpressApp ( )
8797 const options = {
0 commit comments