summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/web_service/web_backend.cpp2
-rw-r--r--src/web_service/web_backend.h3
2 files changed, 4 insertions, 1 deletions
diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp
index 3a3f44dc2..5df4df5eb 100644
--- a/src/web_service/web_backend.cpp
+++ b/src/web_service/web_backend.cpp
@@ -24,6 +24,7 @@ Client::JWTCache Client::jwt_cache{};
24 24
25Client::Client(const std::string& host, const std::string& username, const std::string& token) 25Client::Client(const std::string& host, const std::string& username, const std::string& token)
26 : host(host), username(username), token(token) { 26 : host(host), username(username), token(token) {
27 std::lock_guard<std::mutex> lock(jwt_cache.mutex);
27 if (username == jwt_cache.username && token == jwt_cache.token) { 28 if (username == jwt_cache.username && token == jwt_cache.token) {
28 jwt = jwt_cache.jwt; 29 jwt = jwt_cache.jwt;
29 } 30 }
@@ -116,6 +117,7 @@ void Client::UpdateJWT() {
116 if (result.result_code != Common::WebResult::Code::Success) { 117 if (result.result_code != Common::WebResult::Code::Success) {
117 LOG_ERROR(WebService, "UpdateJWT failed"); 118 LOG_ERROR(WebService, "UpdateJWT failed");
118 } else { 119 } else {
120 std::lock_guard<std::mutex> lock(jwt_cache.mutex);
119 jwt_cache.username = username; 121 jwt_cache.username = username;
120 jwt_cache.token = token; 122 jwt_cache.token = token;
121 jwt_cache.jwt = jwt = result.returned_data; 123 jwt_cache.jwt = jwt = result.returned_data;
diff --git a/src/web_service/web_backend.h b/src/web_service/web_backend.h
index 549bcce29..d75fbcc15 100644
--- a/src/web_service/web_backend.h
+++ b/src/web_service/web_backend.h
@@ -5,7 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <functional> 7#include <functional>
8#include <future> 8#include <mutex>
9#include <string> 9#include <string>
10#include <tuple> 10#include <tuple>
11#include <httplib.h> 11#include <httplib.h>
@@ -81,6 +81,7 @@ private:
81 std::unique_ptr<httplib::Client> cli; 81 std::unique_ptr<httplib::Client> cli;
82 82
83 struct JWTCache { 83 struct JWTCache {
84 std::mutex mutex;
84 std::string username; 85 std::string username;
85 std::string token; 86 std::string token;
86 std::string jwt; 87 std::string jwt;