From af88d0552d41a946186e4f664aba4939cd5ce660 Mon Sep 17 00:00:00 2001 From: Tobasco99 Date: Tue, 24 Sep 2024 18:51:02 +0200 Subject: [PATCH] add auth to training --- src/bot.manager.widget.js | 7 ++++++- src/model-training.js | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/bot.manager.widget.js b/src/bot.manager.widget.js index c80bb13d..d339d7fc 100644 --- a/src/bot.manager.widget.js +++ b/src/bot.manager.widget.js @@ -52,8 +52,13 @@ class BotManagerWidget extends LitElement { if (!endpoint) { return; } + const accessToken = localStorage.getItem("access_token"); - fetch(endpoint + "/models/") + fetch(endpoint + "/models/", { + headers: { + "Authorization": `Bearer ${accessToken}` + } + }) .then((response) => { if ( response.ok && diff --git a/src/model-training.js b/src/model-training.js index 14cd6938..5ade7ace 100644 --- a/src/model-training.js +++ b/src/model-training.js @@ -309,6 +309,9 @@ class ModelTraining extends LitElement { markdownTrainingData: _this.editor.getText(), }), contentType: "application/json", + headers: { + "Authorization": "Bearer " + localStorage.getItem("access_token"), + }, success: function (data, textStatus, jqXHR) { $(_this.htmlQuery("#trainingStatus")).text(data); }, @@ -413,6 +416,9 @@ class ModelTraining extends LitElement { type: "GET", url: trainingStatusUrl, contentType: "text/plain", + headers: { + "Authorization": "Bearer " + localStorage.getItem("access_token"), + }, success: function (data, textStatus, jqXHR) { $(_this.htmlQuery("#trainingStatus")).text(data); }, @@ -435,6 +441,9 @@ class ModelTraining extends LitElement { $.ajax({ type: "POST", url: trainingStatusUrl + name, + headers: { + "Authorization": "Bearer " + localStorage.getItem("access_token"), + }, data: trainingData, contentType: "text/plain", success: function (data, textStatus, jqXHR) { @@ -460,6 +469,9 @@ class ModelTraining extends LitElement { type: "GET", url: trainingStatusUrl + name, contentType: "text/plain", + headers: { + "Authorization": "Bearer " + localStorage.getItem("access_token"), + }, success: function (data, textStatus, jqXHR) { $(_this.htmlQuery("#trainingStatus")).text("Data loaded."); _this.editor.setText(data); @@ -480,6 +492,9 @@ class ModelTraining extends LitElement { type: "GET", url: trainingStatusUrl + "/training/", contentType: "application/json", + headers: { + "Authorization": "Bearer " + localStorage.getItem("access_token"), + }, success: function (data, textStatus, jqXHR) { if (textStatus !== "success") { return;