added authorization by token

This commit is contained in:
Daria Golova
2022-06-16 14:30:41 +03:00
parent 81f5ec2741
commit 632b98a81a

View File

@@ -11,8 +11,8 @@ function handleRequest(method, url, attempts, body) {
.catch(err => --attempts > 0 ? internalRequest() : reject(err)) .catch(err => --attempts > 0 ? internalRequest() : reject(err))
})() })()
}) })
.then((res) => res.json()) .then((res) => res.json())
.catch(() => []) .catch(() => [])
}; };
/** /**
@@ -23,9 +23,13 @@ function handleRequest(method, url, attempts, body) {
function request(method, url, body) { function request(method, url, body) {
let controller = new AbortController; let controller = new AbortController;
let requestOptions = {}; let requestOptions = {};
if (!registrationStore.tokenKey) return Promise.reject();
if (method === 'GET' || method === 'DELETE'){ if (method === 'GET' || method === 'DELETE'){
requestOptions = { requestOptions = {
method: method, method: method,
headers: {
Authorization: `Token ${registrationStore.tokenKey}`,
},
signal: controller.signal, signal: controller.signal,
} }
}; };
@@ -33,6 +37,7 @@ function request(method, url, body) {
requestOptions = { requestOptions = {
method: method, method: method,
headers: { headers: {
Authorization: `Token ${registrationStore.tokenKey}`,
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },