Commit 45e0f181 authored by Nicolas Mérigot's avatar Nicolas Mérigot

fix: avoid infinite call

parent 1e213581
Pipeline #1995 passed with stage
in 37 seconds
...@@ -17,6 +17,7 @@ class SIBOidc extends HTMLElement { ...@@ -17,6 +17,7 @@ class SIBOidc extends HTMLElement {
this.user = null; this.user = null;
// duplicate default settings in this.settings // duplicate default settings in this.settings
this.settings = Object.assign({}, defaultSettings); this.settings = Object.assign({}, defaultSettings);
this.oidcStatus = 'idle';
} }
async connectedCallback() { async connectedCallback() {
...@@ -55,23 +56,30 @@ class SIBOidc extends HTMLElement { ...@@ -55,23 +56,30 @@ class SIBOidc extends HTMLElement {
} }
// try to get user through OIDC Manager // try to get user through OIDC Manager
const user = await this.manager.getUser(); let user = await this.manager.getUser();
if (user) { if (user) {
this.user = user; this.user = user;
return user; return user;
} }
try { if (this.oidcStatus === 'idle') {
const user = await this.manager.signinRedirectCallback(); this.oidcStatus = 'working';
location.href = user.state; try {
return user; user = await this.manager.signinRedirectCallback();
} catch (e) { location.href = decodeURIComponent(user.state.url);
this.manager.signinRedirect({ return user;
state: location.href, } catch(e) {
}); console.log(e);
throw `Can't get user, redirect to OIDC authority ${this.settings.authority}`; await this.manager.signinRedirect({
state: {
url: encodeURIComponent(location.href),
},
});
throw `Can't get user, redirect to OIDC authority ${this.settings.authority}`;
}
} }
return undefined;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment