Commit 6342dc30 authored by Samir Sadyhov's avatar Samir Sadyhov 🤔

ApiClient добавлена авторизация дофолтного юзера конструктора

parent d2dcc2ce
...@@ -2,14 +2,15 @@ this.ApiClient = class { ...@@ -2,14 +2,15 @@ this.ApiClient = class {
constructor() { constructor() {
this._baseURL = `${window.location.origin}/Synergy`; this._baseURL = `${window.location.origin}/Synergy`;
this._authHeader = this._buildAuthHeader(); this._authHeader = this._buildAuthHeader();
this._defaultAuthHeader = this._buildDefaultAuthHeader();
this._requestInterceptors = []; this._requestInterceptors = [];
this._responseInterceptors = []; this._responseInterceptors = [];
} }
async request({ url, method = 'GET', body, headers = {} }) { async request({ url, method = 'GET', body, headers = {}, defaultUser = false }) {
let finalHeaders = this._normalizeHeaders({ let finalHeaders = this._normalizeHeaders({
authorization: this._authHeader, authorization: defaultUser ? this._defaultAuthHeader : this._authHeader,
...headers, ...headers,
}); });
...@@ -104,6 +105,16 @@ this.ApiClient = class { ...@@ -104,6 +105,16 @@ this.ApiClient = class {
} }
} }
_buildDefaultAuthHeader() {
const {defaultUser, defaultUserPassword} = Cons.getCurrentApp();
const base64 = btoa(
new TextEncoder().encode(`${defaultUser}:${defaultUserPassword}`)
.reduce((str, byte) => str + String.fromCharCode(byte), '')
);
return `Basic ${base64}`;
}
_normalizeHeaders(headers = {}) { _normalizeHeaders(headers = {}) {
const result = {}; const result = {};
for (const key in headers) { for (const key in headers) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment