From 330707313d086e4b2d372ede1aea4dd94b82e4f6 Mon Sep 17 00:00:00 2001 From: Yogesh Choudhary Date: Mon, 21 Oct 2024 16:39:58 +0530 Subject: [PATCH] fix: included auth header for custom agents contribute source --- web/src/lib/components/SettingsAgent.svelte | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/web/src/lib/components/SettingsAgent.svelte b/web/src/lib/components/SettingsAgent.svelte index 6bdc09d..df53a84 100644 --- a/web/src/lib/components/SettingsAgent.svelte +++ b/web/src/lib/components/SettingsAgent.svelte @@ -38,6 +38,16 @@ return; } + let accessToken = localStorage.getItem("accessToken"); + + const headers = { + "Content-Type": "application/json", + }; + + if (accessToken && accessToken.length > 0) { + headers.Authorization = "Bearer " + accessToken; + } + for (let field of formData) { const [key, value] = field; @@ -57,9 +67,7 @@ try { const response = await fetch(ACTION_URL, { method: "POST", - headers: { - "Content-Type": "application/json", - }, + headers: headers, body: JSON.stringify(requestBody), });