-
Notifications
You must be signed in to change notification settings - Fork 7
Frontend/auto logout #1203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
isabeleliassen
merged 6 commits into
csg-org:main
from
InspiringApps:frontend/auto-logout
Nov 21, 2025
Merged
Frontend/auto logout #1203
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0812dee
WIP: auto logout
jsandoval81 e993003
WIP: auto logout
jsandoval81 e92d526
WIP: auto logout
jsandoval81 d82e1dd
WIP: auto logout
jsandoval81 41c956a
WIP: auto logout
jsandoval81 3686ba1
PR review feedback
jsandoval81 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| </ul> | ||
| </template> | ||
| </Modal> | ||
| <AutoLogout /> | ||
| </div> | ||
| </template> | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // | ||
| // AutoLogout.less | ||
| // CompactConnect | ||
| // | ||
| // Created by InspiringApps on 11/13/2025. | ||
| // | ||
|
|
||
| .auto-logout-modal { | ||
| color: @fontColor; | ||
|
|
||
| :deep(.modal-container) { | ||
| width: 95%; | ||
| max-width: 60rem; | ||
| padding: 2rem; | ||
|
|
||
| @media @tabletWidth { | ||
| padding: 4rem; | ||
| } | ||
|
|
||
| .header-container { | ||
| justify-content: center; | ||
| margin-bottom: 1rem; | ||
| } | ||
|
|
||
| .modal-content { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
|
|
||
| .description-container { | ||
| text-align: center; | ||
| } | ||
|
|
||
| .action-button-row { | ||
| display: flex; | ||
| flex-direction: column; | ||
| width: 100%; | ||
| margin-top: 4rem; | ||
|
|
||
| @media @desktopWidth { | ||
| flex-direction: row; | ||
| flex-wrap: wrap; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .action-button { | ||
| width: 100%; | ||
| margin-bottom: 1rem; | ||
|
|
||
| @media @desktopWidth { | ||
| width: auto; | ||
|
|
||
| &:not(:first-child) { | ||
| margin-left: 2.4rem; | ||
| } | ||
| } | ||
|
|
||
| .input-button, | ||
| .input-submit { | ||
| width: 100%; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // | ||
| // AutoLogout.spec.ts | ||
| // CompactConnect | ||
| // | ||
| // Created by InspiringApps on 11/13/2025. | ||
| // | ||
|
|
||
| import { expect } from 'chai'; | ||
| import { mountShallow } from '@tests/helpers/setup'; | ||
| import AutoLogout from '@components/AutoLogout/AutoLogout.vue'; | ||
|
|
||
| describe('AutoLogout component', async () => { | ||
| it('should mount the component', async () => { | ||
| const wrapper = await mountShallow(AutoLogout); | ||
|
|
||
| expect(wrapper.exists()).to.equal(true); | ||
| expect(wrapper.findComponent(AutoLogout).exists()).to.equal(true); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| // | ||
| // AutoLogout.ts | ||
| // CompactConnect | ||
| // | ||
| // Created by InspiringApps on 11/13/2025. | ||
| // | ||
|
|
||
| import { | ||
| Component, | ||
| mixins, | ||
| Watch, | ||
| toNative | ||
| } from 'vue-facing-decorator'; | ||
| import { reactive, nextTick } from 'vue'; | ||
| import { autoLogoutConfig } from '@/app.config'; | ||
| import MixinForm from '@components/Forms/_mixins/form.mixin'; | ||
| import Modal from '@components/Modal/Modal.vue'; | ||
| import InputSubmit from '@components/Forms/InputSubmit/InputSubmit.vue'; | ||
| import { FormInput } from '@/models/FormInput/FormInput.model'; | ||
|
|
||
| @Component({ | ||
| name: 'AutoLogout', | ||
| components: { | ||
| Modal, | ||
| InputSubmit, | ||
| }, | ||
| }) | ||
| class AutoLogout extends mixins(MixinForm) { | ||
| // | ||
| // Data | ||
| // | ||
| gracePeriodTimerId: number | null = null; | ||
| gracePeriodExtendEnabled = true; | ||
| eventsController: AbortController | null = null; | ||
| eventDebounceMs = 1000; | ||
| activityResetEventTypes = [ | ||
| 'mousemove', | ||
| 'mousedown', | ||
| 'click', | ||
| 'keypress', | ||
| 'touchstart', | ||
| 'touchend', | ||
| 'touchmove', | ||
| 'onscroll', | ||
| 'wheel', | ||
| 'mousewheel', | ||
| ]; | ||
|
|
||
| // | ||
| // Lifecycle | ||
| // | ||
| async created() { | ||
| if (this.userStore.isLoggedIn) { | ||
| this.initFormInputs(); | ||
| this.startAutoLogoutInactivityTimer(); | ||
| } | ||
| } | ||
|
|
||
| async beforeUnmount() { | ||
| this.removeAutoLogoutEvents(); | ||
| } | ||
|
|
||
| // | ||
| // Computed | ||
| // | ||
| get userStore() { | ||
| return this.$store.state.user; | ||
| } | ||
|
|
||
| // | ||
| // Methods | ||
| // | ||
| initFormInputs(): void { | ||
| this.formData = reactive({ | ||
| stayLoggedIn: new FormInput({ | ||
| isSubmitInput: true, | ||
| id: 'auto-logout-cancel-button', | ||
| }), | ||
| }); | ||
| } | ||
|
|
||
| startAutoLogoutInactivityTimer(): void { | ||
| const { isLoggedIn, isAutoLogoutWarning } = this.userStore; | ||
| const abortController = new AbortController(); | ||
| const eventHandler = (event) => { | ||
| autoLogoutConfig.LOG(`event: ${event.type}`); | ||
| this.$store.dispatch('user/startAutoLogoutInactivityTimer'); | ||
| this.startAutoLogoutInactivityTimer(); | ||
| }; | ||
| const debouncedEventHandler = this.debounce(eventHandler, this.eventDebounceMs); | ||
|
|
||
| this.removeAutoLogoutEvents(); | ||
|
|
||
| if (isLoggedIn && !isAutoLogoutWarning) { | ||
| this.$store.dispatch('user/startAutoLogoutInactivityTimer'); | ||
| this.eventsController = abortController; | ||
| this.activityResetEventTypes.forEach((eventType) => { | ||
| document.addEventListener(eventType, debouncedEventHandler, { | ||
| capture: false, | ||
| once: true, | ||
| passive: true, | ||
| signal: abortController.signal, | ||
| }); | ||
| }); | ||
| autoLogoutConfig.LOG(`event listeners created`); | ||
| } | ||
| } | ||
|
|
||
| startAutoLogoutGracePeriodTimer(): void { | ||
| const { isLoggedIn, isAutoLogoutWarning } = this.userStore; | ||
|
|
||
| if (isLoggedIn && isAutoLogoutWarning) { | ||
| autoLogoutConfig.LOG(`grace period started`); | ||
| this.gracePeriodTimerId = window.setTimeout(() => { | ||
| autoLogoutConfig.LOG(`grace period logging out...`); | ||
| this.gracePeriodExtendEnabled = false; | ||
| this.$router.push({ name: 'Logout' }); | ||
| }, autoLogoutConfig.GRACE_PERIOD_MS); | ||
| } | ||
| } | ||
|
|
||
| clearAutoLogoutGracePeriodTimer(): void { | ||
| const { gracePeriodTimerId } = this; | ||
|
|
||
| if (gracePeriodTimerId) { | ||
| clearTimeout(gracePeriodTimerId); | ||
| this.gracePeriodTimerId = null; | ||
| } | ||
| } | ||
|
|
||
| debounce(callback, delayMs): () => void { | ||
| let timeout; | ||
|
|
||
| return (...args) => { | ||
| clearTimeout(timeout); | ||
| timeout = setTimeout(() => callback.apply(this, args), delayMs); | ||
| }; | ||
| } | ||
|
|
||
| staySignedIn(): void { | ||
| this.clearAutoLogoutGracePeriodTimer(); | ||
| this.$store.dispatch('user/updateAutoLogoutWarning', false); | ||
| this.startAutoLogoutInactivityTimer(); | ||
| } | ||
|
|
||
| focusTrapAutoLogoutModal(event: KeyboardEvent): void { | ||
| const firstTabIndex = document.getElementById('auto-logout-cancel-button'); | ||
| const lastTabIndex = document.getElementById('auto-logout-cancel-button'); | ||
|
|
||
| if (event.shiftKey) { | ||
| // shift + tab to last input | ||
| if (document.activeElement === firstTabIndex) { | ||
| lastTabIndex?.focus(); | ||
| event.preventDefault(); | ||
| } | ||
| } else if (document.activeElement === lastTabIndex) { | ||
| // Tab to first input | ||
| firstTabIndex?.focus(); | ||
| event.preventDefault(); | ||
| } | ||
| } | ||
|
|
||
| removeAutoLogoutEvents(): void { | ||
| const { eventsController } = this; | ||
|
|
||
| if (eventsController) { | ||
| eventsController.abort(); | ||
| this.eventsController = null; | ||
| autoLogoutConfig.LOG(`event listeners removed`); | ||
| } | ||
| } | ||
|
|
||
| // | ||
| // Watchers | ||
| // | ||
| @Watch('userStore.isLoggedIn') async handleLoginUpdate() { | ||
| if (!this.userStore.isLoggedIn) { | ||
| this.removeAutoLogoutEvents(); | ||
| } else { | ||
| this.startAutoLogoutInactivityTimer(); | ||
| } | ||
| } | ||
|
|
||
| @Watch('userStore.isAutoLogoutWarning') async handleAutoLogoutWarning() { | ||
| if (this.userStore.isAutoLogoutWarning) { | ||
| this.startAutoLogoutGracePeriodTimer(); | ||
| await nextTick(); | ||
| document.getElementById('auto-logout-cancel-button')?.focus(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default toNative(AutoLogout); | ||
|
|
||
| // export default AutoLogout; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <!-- | ||
| AutoLogout.vue | ||
| CompactConnect | ||
|
|
||
| Created by InspiringApps on 11/13/2025. | ||
| --> | ||
|
|
||
| <template> | ||
| <Modal | ||
| v-if="userStore.isAutoLogoutWarning && gracePeriodExtendEnabled" | ||
| modalId="auto-logout-modal" | ||
| class="auto-logout-modal" | ||
| :title="$t('account.autoLogoutWarningTitle')" | ||
| :showActions="false" | ||
| @keydown.tab="focusTrapAutoLogoutModal($event)" | ||
| @keyup.esc="staySignedIn" | ||
| > | ||
| <template v-slot:content> | ||
| <div | ||
| class="modal-content auto-logout-modal-content" | ||
| aria-live="assertive" | ||
| role="status" | ||
| > | ||
| <form class="auto-logout-form" @submit.prevent="staySignedIn"> | ||
| <div class="description-container">{{ $t('account.autoLogoutWarningDescription') }}</div> | ||
| <div class="action-button-row"> | ||
| <InputSubmit | ||
| :formInput="formData.stayLoggedIn" | ||
| class="action-button auto-logout-cancel-button" | ||
| :label="$t('account.autoLogoutStaySignedIn')" | ||
| /> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </template> | ||
| </Modal> | ||
| </template> | ||
|
|
||
| <script lang="ts" src="./AutoLogout.ts"></script> | ||
| <style scoped lang="less" src="./AutoLogout.less"></style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.