Skip to content
Snippets Groups Projects
Commit cb7e78cb authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

jsonld: don't wait for a token for the entity lookup

We can access that API without a token.
parent 22fbe664
No related branches found
No related tags found
No related merge requests found
......@@ -152,7 +152,7 @@ export class AuthKeycloak extends AdapterLitElement {
}
this.sendSetPropertyEvent('auth', auth);
JSONLD.doInitializationOnce(this.entryPointUrl, this.token);
JSONLD.doInitializationOnce(this.entryPointUrl);
}
_setLoginStatus(status, force) {
......
......@@ -310,7 +310,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
this.initJSONLD(true);
break;
case "auth":
JSONLD.doInitializationOnce(this.entryPointUrl, this.auth.token);
JSONLD.doInitializationOnce(this.entryPointUrl);
break;
}
});
......
......@@ -41,28 +41,26 @@ export default class JSONLD {
}
/**
* This should be run as soon as an api token is available (can be run multiple times)
* This should be run as soon as possible (can be run multiple times)
*
* @param apiUrl
* @param token
*/
static doInitializationOnce(apiUrl, token) {
// console.log("doInitializationOnce", apiUrl, token);
static doInitializationOnce(apiUrl) {
// console.log("doInitializationOnce", apiUrl);
// check if token is not set or api call was already started
if (!apiUrl || !token || JSONLD.initStarted[apiUrl] !== undefined) {
// check if api call was already started
if (!apiUrl || JSONLD.initStarted[apiUrl] !== undefined) {
return;
}
JSONLD.initStarted[apiUrl] = true;
JSONLD.doInitialization(apiUrl, token);
// console.log("doInitializationOnce Done", apiUrl, token);
JSONLD.doInitialization(apiUrl);
// console.log("doInitializationOnce Done", apiUrl);
}
static doInitialization(apiUrl, token) {
static doInitialization(apiUrl) {
const xhr = new XMLHttpRequest();
xhr.open("GET", apiUrl, true);
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) {
......@@ -143,7 +141,13 @@ export default class JSONLD {
JSONLD.instances[apiUrl] = instance;
// return the initialized JSONLD object
for (const fnc of JSONLD.successFunctions[apiUrl]) if (typeof fnc == 'function') fnc(instance);
if (JSONLD.successFunctions[apiUrl] !== undefined) {
for (const fnc of JSONLD.successFunctions[apiUrl]) {
if (typeof fnc == 'function') {
fnc(instance);
}
}
}
JSONLD.successFunctions[apiUrl] = [];
}
......@@ -154,7 +158,9 @@ export default class JSONLD {
* @param message
*/
static executeFailureFunctions(apiUrl, message = "") {
if (JSONLD.failureFunctions[apiUrl] !== undefined) {
for (const fnc of JSONLD.failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc();
}
JSONLD.failureFunctions[apiUrl] = [];
if (message !== "") {
......
......@@ -199,7 +199,7 @@ export class OrganizationSelect extends AdapterLitElement {
}, {}, this.lang);
break;
case "auth":
JSONLD.doInitializationOnce(this.entryPointUrl, this.auth.token);
JSONLD.doInitializationOnce(this.entryPointUrl);
this.initAuthPersonOnce().then();
break;
default:
......
......@@ -68,7 +68,7 @@ export class PersonProfile extends DBPLitElement {
}
break;
case "auth":
JSONLD.doInitializationOnce(this.entryPointUrl, this.auth.token);
JSONLD.doInitializationOnce(this.entryPointUrl);
break;
default:
}
......
......@@ -291,7 +291,7 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
this.initJSONLD(true);
break;
case "auth":
JSONLD.doInitializationOnce(this.entryPointUrl, this.auth.token);
JSONLD.doInitializationOnce(this.entryPointUrl);
this.active = this.authenticated();
break;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment