Sha256: f2f6427535e09d98470324c8307f502b2ceeeb455ce2e1f53adc69c9a6684d12
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
// https://stackoverflow.com/questions/8578617/inject-a-script-tag-with-remote-src-and-wait-for-it-to-execute function prxInjectScript(src, callback) { const script = document.createElement('script'); script.type = 'text/javascript'; script.async = false; script.src = src; script.onload = function () { script.onload = null; callback(); } document.getElementsByTagName('head')[0].appendChild(script); } document.addEventListener('DOMContentLoaded', function () { const idHost = 'https://<%= PrxAuth::Rails.configuration.id_host %>'; const scriptUrl = idHost + '/widget.js'; prxInjectScript(scriptUrl, function () { const signIn = new PRXSignIn(idHost); signIn.signedIn(function (prx) { const widget = document.getElementById('prx-user-widget'); const account = document.getElementById('prx-user-widget-menu-account'); if (!prx.userinfo) { // Not logged in widget.classList.add('no-user-info'); const url = idHost + '/session?return_to=' + encodeURIComponent(window.location); account.innerHTML = '<a class=sign-in href="' + url + '">Sign in</a>'; } else { // Logged in widget.classList.add('user-info'); const account = document.getElementById('prx-user-widget-menu-account'); account.innerText = prx.userinfo.email; signIn.listApps('prx-user-widget-menu-apps'); } }); }); });
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
prx_auth-rails-1.6.0 | app/assets/javascripts/prx_auth-rails/user_widget.js.erb |