MCPcopy Index your code
hub / github.com/simstudioai/sim / validateChatAuth

Function validateChatAuth

apps/sim/app/api/proxy/tts/stream/route.ts:19–58  ·  view source on GitHub ↗

* Validates chat-based authentication for deployed chat voice mode * Checks if the user has a valid chat auth cookie for the given chatId

(request: NextRequest, chatId: string)

Source from the content-addressed store, hash-verified

17 * Checks if the user has a valid chat auth cookie for the given chatId
18 */
19async function validateChatAuth(request: NextRequest, chatId: string): Promise<boolean> {
20 try {
21 const chatResult = await db
22 .select({
23 id: chat.id,
24 isActive: chat.isActive,
25 authType: chat.authType,
26 password: chat.password,
27 })
28 .from(chat)
29 .where(eq(chat.id, chatId))
30 .limit(1)
31
32 if (chatResult.length === 0 || !chatResult[0].isActive) {
33 logger.warn('Chat not found or inactive for TTS auth:', chatId)
34 return false
35 }
36
37 const chatData = chatResult[0]
38
39 if (chatData.authType === 'public') {
40 return true
41 }
42
43 const cookieName = `chat_auth_${chatId}`
44 const authCookie = request.cookies.get(cookieName)
45
46 if (
47 authCookie &&
48 validateAuthToken(authCookie.value, chatId, chatData.authType, chatData.password)
49 ) {
50 return true
51 }
52
53 return false
54 } catch (error) {
55 logger.error('Error validating chat auth for TTS:', error)
56 return false
57 }
58}
59
60export const POST = withRouteHandler(async (request: NextRequest) => {
61 try {

Callers 1

route.tsFile · 0.70

Calls 5

validateAuthTokenFunction · 0.90
errorMethod · 0.80
warnMethod · 0.65
getMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected