Commit 6a3217dd authored by Clément's avatar Clément

getUser always return same promise

parent 45e0f181
Pipeline #1997 passed with stage
in 27 seconds
......@@ -17,7 +17,6 @@ class SIBOidc extends HTMLElement {
this.user = null;
// duplicate default settings in this.settings
this.settings = Object.assign({}, defaultSettings);
this.oidcStatus = 'idle';
}
async connectedCallback() {
......@@ -25,7 +24,8 @@ class SIBOidc extends HTMLElement {
// initialize OIDC Manager
this.manager = new UserManager(this.settings);
const promise = this.getUser();
this.getUser = () => promise;
const processDOM = async () => {
const user = await this.getUser();
const id = user.profile.website;
......@@ -45,8 +45,8 @@ class SIBOidc extends HTMLElement {
}
disconnectedCallback() {
this.manager = null;
this.user = null;
this.manager = null;
this.user = null;
}
async getUser() {
......@@ -62,24 +62,20 @@ class SIBOidc extends HTMLElement {
this.user = user;
return user;
}
if (this.oidcStatus === 'idle') {
this.oidcStatus = 'working';
try {
user = await this.manager.signinRedirectCallback();
location.href = decodeURIComponent(user.state.url);
return user;
} catch(e) {
console.log(e);
await this.manager.signinRedirect({
state: {
url: encodeURIComponent(location.href),
},
});
throw `Can't get user, redirect to OIDC authority ${this.settings.authority}`;
}
try {
user = await this.manager.signinRedirectCallback();
location.href = decodeURIComponent(user.state.url);
return user;
} catch (e) {
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