Commit 84ccf4a7 authored by Clément's avatar Clément

bugfix process bind-user when DOM is ready

parent ab0efc3c
......@@ -28,7 +28,7 @@
<pre id="output"></pre>
<script>
sib.oidc.getUser(user => {
sib.oidc.getUser().then(user => {
output.textContent = JSON.stringify(user, null, 2);
});
</script>
......
{
const sib = { oidc: {} };
window.sib = sib;
const defaultSettings = {
redirect_uri: location.origin,
// authority: 'https://test-paris.happy-dev.fr/openid/',
......@@ -21,12 +18,21 @@
const manager = new Oidc.UserManager(settings);
const promise = tryToGetUserOrConnect();
sib.oidc.getUser = cb => {
promise.then(cb);
const sib = {
oidc: {
getUser: () => promise,
user: null,
},
};
window.sib = sib;
sib.oidc.getUser(user => {
sib.oidc.getUser().then(user => {
sib.oidc.user = user;
});
document.addEventListener('DOMContentLoaded', async () => {
const user = await sib.oidc.getUser();
const id = user.profile.website;
const selector = `[bind-user]:not([data-src="${id}"])`;
const elements = document.querySelectorAll(selector);
......@@ -45,13 +51,10 @@
location.href = user.state;
return user;
} catch (e) {
try {
manager.signinRedirect({
state: location.href,
});
} catch (e) {
console.log(e);
}
manager.signinRedirect({
state: location.href,
});
throw `Can't get user, redirect to OIDC authority ${settings.authority}`;
}
}
}
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