From 816cae3aacd84a2e0db7f333e24b391dd3078e84 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Thu, 6 Mar 2025 09:30:30 +0530 Subject: [PATCH] fix: update bearer to capital case and handle undefined (#7226) --- frontend/src/api/channels/createWebhook.ts | 14 ++++++++------ frontend/src/api/channels/editWebhook.ts | 15 +++++++++------ frontend/src/api/channels/testWebhook.ts | 14 ++++++++------ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/frontend/src/api/channels/createWebhook.ts b/frontend/src/api/channels/createWebhook.ts index 67a0de7a7b..f63cb2e32b 100644 --- a/frontend/src/api/channels/createWebhook.ts +++ b/frontend/src/api/channels/createWebhook.ts @@ -9,19 +9,21 @@ const create = async ( ): Promise | ErrorResponse> => { try { let httpConfig = {}; + const username = props.username ? props.username.trim() : ''; + const password = props.password ? props.password.trim() : ''; - if (props.username !== '' && props.password !== '') { + if (username !== '' && password !== '') { httpConfig = { basic_auth: { - username: props.username, - password: props.password, + username, + password, }, }; - } else if (props.username === '' && props.password !== '') { + } else if (username === '' && password !== '') { httpConfig = { authorization: { - type: 'bearer', - credentials: props.password, + type: 'Bearer', + credentials: password, }, }; } diff --git a/frontend/src/api/channels/editWebhook.ts b/frontend/src/api/channels/editWebhook.ts index a96850c2db..f6a661644f 100644 --- a/frontend/src/api/channels/editWebhook.ts +++ b/frontend/src/api/channels/editWebhook.ts @@ -9,18 +9,21 @@ const editWebhook = async ( ): Promise | ErrorResponse> => { try { let httpConfig = {}; - if (props.username !== '' && props.password !== '') { + const username = props.username ? props.username.trim() : ''; + const password = props.password ? props.password.trim() : ''; + + if (username !== '' && password !== '') { httpConfig = { basic_auth: { - username: props.username, - password: props.password, + username, + password, }, }; - } else if (props.username === '' && props.password !== '') { + } else if (username === '' && password !== '') { httpConfig = { authorization: { - type: 'bearer', - credentials: props.password, + type: 'Bearer', + credentials: password, }, }; } diff --git a/frontend/src/api/channels/testWebhook.ts b/frontend/src/api/channels/testWebhook.ts index 4b915e9a3a..26c93f3d4a 100644 --- a/frontend/src/api/channels/testWebhook.ts +++ b/frontend/src/api/channels/testWebhook.ts @@ -9,19 +9,21 @@ const testWebhook = async ( ): Promise | ErrorResponse> => { try { let httpConfig = {}; + const username = props.username ? props.username.trim() : ''; + const password = props.password ? props.password.trim() : ''; - if (props.username !== '' && props.password !== '') { + if (username !== '' && password !== '') { httpConfig = { basic_auth: { - username: props.username, - password: props.password, + username, + password, }, }; - } else if (props.username === '' && props.password !== '') { + } else if (username === '' && password !== '') { httpConfig = { authorization: { - type: 'bearer', - credentials: props.password, + type: 'Bearer', + credentials: password, }, }; }