Skip to content

Commit

Permalink
Add update loop and login nextRequest return leg param
Browse files Browse the repository at this point in the history
  • Loading branch information
dauglyon committed Feb 6, 2025
1 parent 1e65775 commit 9065e43
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ <h1>Sign in</h1>
<input id="login_not_ok"
type="button"
class='btn btn-jupyter form-control hidden'
value='Please log in to KBase to continue'
value='Log in to KBase to continue'
tabindex="3" />
<input id="login_submit"
type="submit"
class='btn btn-jupyter form-control hidden'
value='Log In with your KBase Account'
value='Log in with your KBase Account'
tabindex="3" />
<div class="feedback-widget hidden">
<i class="fa fa-spinner"></i>
Expand Down Expand Up @@ -86,21 +86,38 @@ <h1>Sign in</h1>
const enviromentOrigin = "{{ kbase_origin }}"

$('#login_not_ok').click(function () {
window.location.href = enviromentOrigin + '/login';
window.location.href = enviromentOrigin + '/login?nextRequest=%22/cdm/redirect%22';
})

// Check KBase token is present and valid
checkKBaseCookie().then((username) => {
if (username) {
const buttonText = 'Log in with KBase as "' + username + '"';
$('#login_submit').attr('value', buttonText);
$('#login_submit').toggleClass('hidden', false);
$('#login_not_ok').toggleClass('hidden', true);
} else {
$('#login_submit').toggleClass('hidden', true);
$('#login_not_ok').toggleClass('hidden', false);
// Initial state update
updateState();
// Check for cookie changes in other windows w/ useInterval,
// in case someone goes to another window to log in
// instead of clicking through our flow.
let currentCookie = "";
setInterval(() => {
const tokenCookie = getCookie('kbase_session');
// if cookie changes
if (tokenCookie !== currentCookie) {
currentCookie = tokenCookie;
updateState();
}
})
}, 200);

function updateState() {
// Check KBase token is present and valid
checkKBaseCookie().then((username) => {
if (username) {
const buttonText = 'Log in with KBase as "' + username + '"';
$('#login_submit').attr('value', buttonText);
$('#login_submit').toggleClass('hidden', false);
$('#login_not_ok').toggleClass('hidden', true);
} else {
$('#login_submit').toggleClass('hidden', true);
$('#login_not_ok').toggleClass('hidden', false);
}
})
}

function checkKBaseCookie() {
const tokenCookie = getCookie('kbase_session');
Expand Down

0 comments on commit 9065e43

Please sign in to comment.