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 { ...@@ -152,7 +152,7 @@ export class AuthKeycloak extends AdapterLitElement {
} }
this.sendSetPropertyEvent('auth', auth); this.sendSetPropertyEvent('auth', auth);
JSONLD.doInitializationOnce(this.entryPointUrl, this.token); JSONLD.doInitializationOnce(this.entryPointUrl);
} }
_setLoginStatus(status, force) { _setLoginStatus(status, force) {
......
...@@ -310,7 +310,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) { ...@@ -310,7 +310,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
this.initJSONLD(true); this.initJSONLD(true);
break; break;
case "auth": case "auth":
JSONLD.doInitializationOnce(this.entryPointUrl, this.auth.token); JSONLD.doInitializationOnce(this.entryPointUrl);
break; break;
} }
}); });
......
...@@ -41,28 +41,26 @@ export default class JSONLD { ...@@ -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 apiUrl
* @param token
*/ */
static doInitializationOnce(apiUrl, token) { static doInitializationOnce(apiUrl) {
// console.log("doInitializationOnce", apiUrl, token); // console.log("doInitializationOnce", apiUrl);
// check if token is not set or api call was already started // check if api call was already started
if (!apiUrl || !token || JSONLD.initStarted[apiUrl] !== undefined) { if (!apiUrl || JSONLD.initStarted[apiUrl] !== undefined) {
return; return;
} }
JSONLD.initStarted[apiUrl] = true; JSONLD.initStarted[apiUrl] = true;
JSONLD.doInitialization(apiUrl, token); JSONLD.doInitialization(apiUrl);
// console.log("doInitializationOnce Done", apiUrl, token); // console.log("doInitializationOnce Done", apiUrl);
} }
static doInitialization(apiUrl, token) { static doInitialization(apiUrl) {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open("GET", apiUrl, true); xhr.open("GET", apiUrl, true);
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.onreadystatechange = function () { xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) { if (xhr.readyState !== 4) {
...@@ -143,7 +141,13 @@ export default class JSONLD { ...@@ -143,7 +141,13 @@ export default class JSONLD {
JSONLD.instances[apiUrl] = instance; JSONLD.instances[apiUrl] = instance;
// return the initialized JSONLD object // 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] = []; JSONLD.successFunctions[apiUrl] = [];
} }
...@@ -154,7 +158,9 @@ export default class JSONLD { ...@@ -154,7 +158,9 @@ export default class JSONLD {
* @param message * @param message
*/ */
static executeFailureFunctions(apiUrl, message = "") { static executeFailureFunctions(apiUrl, message = "") {
if (JSONLD.failureFunctions[apiUrl] !== undefined) {
for (const fnc of JSONLD.failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc(); for (const fnc of JSONLD.failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc();
}
JSONLD.failureFunctions[apiUrl] = []; JSONLD.failureFunctions[apiUrl] = [];
if (message !== "") { if (message !== "") {
......
...@@ -199,7 +199,7 @@ export class OrganizationSelect extends AdapterLitElement { ...@@ -199,7 +199,7 @@ export class OrganizationSelect extends AdapterLitElement {
}, {}, this.lang); }, {}, this.lang);
break; break;
case "auth": case "auth":
JSONLD.doInitializationOnce(this.entryPointUrl, this.auth.token); JSONLD.doInitializationOnce(this.entryPointUrl);
this.initAuthPersonOnce().then(); this.initAuthPersonOnce().then();
break; break;
default: default:
......
...@@ -68,7 +68,7 @@ export class PersonProfile extends DBPLitElement { ...@@ -68,7 +68,7 @@ export class PersonProfile extends DBPLitElement {
} }
break; break;
case "auth": case "auth":
JSONLD.doInitializationOnce(this.entryPointUrl, this.auth.token); JSONLD.doInitializationOnce(this.entryPointUrl);
break; break;
default: default:
} }
......
...@@ -291,7 +291,7 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) { ...@@ -291,7 +291,7 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
this.initJSONLD(true); this.initJSONLD(true);
break; break;
case "auth": case "auth":
JSONLD.doInitializationOnce(this.entryPointUrl, this.auth.token); JSONLD.doInitializationOnce(this.entryPointUrl);
this.active = this.authenticated(); this.active = this.authenticated();
break; break;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment