Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions app/javascript/packs/session-timeout-ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ interface PingResponse {
*/
live: boolean;

/**
* Time remaining in active session, in seconds.
*/
remaining: number;

/**
* ISO8601-formatted date string for session timeout.
*/
Expand Down Expand Up @@ -64,7 +59,7 @@ function handleTimeout(redirectURL: string) {
}

function success(data: PingResponse) {
let timeRemaining = data.remaining * 1000;
let timeRemaining = new Date(data.timeout).valueOf() - Date.now();
const showWarning = timeRemaining < warning;

if (!data.live) {
Expand All @@ -80,9 +75,6 @@ function success(data: PingResponse) {
countdownEl.expiration = new Date(data.timeout);
countdownEl.start();
});
} else {
modal.hide();
countdownEls.forEach((countdownEl) => countdownEl.stop());
}

if (timeRemaining < frequency) {
Expand All @@ -102,9 +94,11 @@ function ping() {
}

function keepalive() {
request('/sessions/keepalive', { method: 'POST' })
.then(success)
.catch((error) => notifyNewRelic(error, 'keepalive'));
modal.hide();
countdownEls.forEach((countdownEl) => countdownEl.stop());
request('/sessions/keepalive', { method: 'POST' }).catch((error) => {
notifyNewRelic(error, 'keepalive');
});
}

keepaliveEl?.addEventListener('click', keepalive, false);
Expand Down
17 changes: 8 additions & 9 deletions spec/features/users/sign_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,14 @@
end

scenario 'user can continue browsing with refreshed CSRF token' do
expect do
click_button t('notices.timeout_warning.signed_in.continue')
expect(page).not_to have_css('.usa-js-modal--active', wait: 5)
end.to change { find('[name=authenticity_token]', visible: false).value }

expect(current_path).to eq forget_all_browsers_path

click_button t('forms.buttons.confirm')
expect(current_path).to eq account_path
token = find('[name=authenticity_token]', visible: false).value
click_button t('notices.timeout_warning.signed_in.continue')
expect(page).not_to have_css('.usa-js-modal--active')
expect(page).to have_css(
"[name=authenticity_token]:not([value='#{token}'])",
visible: false,
wait: 5,
)
end

scenario 'user has option to sign out' do
Expand Down