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

auth: in case anything regarding fetching the user fails, just give up

Instead of throwing an error.

So the login process completes, but the user will not have any roles in that case.
This helps in case the API isn't set up but the user wants to try the frontend app.
parent 9f70e1cf
No related branches found
No related tags found
No related merge requests found
Pipeline #63515 passed
......@@ -84,27 +84,13 @@ export class AuthKeycloak extends AdapterLitElement {
async _fetchUser(userId) {
let jsonld;
try {
jsonld = await JSONLD.getInstance(this.entryPointUrl, this.lang);
} catch(error) {
// Server is down, just give up.
return {
roles: [],
};
}
jsonld = await JSONLD.getInstance(this.entryPointUrl, this.lang);
let baseUrl = '';
try {
baseUrl = jsonld.getApiUrlForEntityName("FrontendUser");
} catch(error) {
// backwards compat
try {
baseUrl = jsonld.getApiUrlForEntityName("Person");
} catch(error) {
// There are no entities, just give up.
return {
roles: [],
};
}
baseUrl = jsonld.getApiUrlForEntityName("Person");
}
const apiUrl = baseUrl + '/' + encodeURIComponent(userId);
......@@ -137,7 +123,16 @@ export class AuthKeycloak extends AdapterLitElement {
let userChanged = (userId !== this._userId);
if (userChanged) {
this._userId = userId;
let user = await this._fetchUser(userId);
let user;
try {
user = await this._fetchUser(userId);
} catch (error) {
// In case fetching the user failed then likely the API backend
// is not set up or broken. Return a user without any roles so we
// can show something at least.
console.error(error);
user = {roles: []};
}
if (userId === this._userId) {
this._user = user;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment