Fix: User login on production.

This commit is contained in:
2024-11-15 15:55:12 +00:00
parent 569508b408
commit 21e7154672
9 changed files with 115 additions and 53 deletions

File diff suppressed because one or more lines are too long

View File

@@ -4,21 +4,25 @@ import DOM from './dom.js';
export default class API {
static getCsrfToken() {
// return document.querySelectorAll('meta[name=' + nameCSRFToken + ']').getAttribute('content');
return document.querySelector(idCSRFToken).getAttribute('content');
}
static async request(hashEndpoint, method = 'GET', data = null, params = null) {
const url = API.getUrlFromHash(hashEndpoint, params);
const csrfToken = API.getCsrfToken();
const options = {
method,
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': API.getCsrfToken()
[flagCsrfToken]: csrfToken,
}
};
if (data && (method === 'POST' || method === 'PUT' || method === 'PATCH')) {
data = {
...data,
[flagCsrfToken]: csrfToken,
};
options.body = JSON.stringify(data);
}