feat(webui): logout when session expired

This commit is contained in:
Gauthier Roebroeck 2022-03-03 08:51:55 +08:00
parent e345d6f9ef
commit 093610e186
6 changed files with 28 additions and 3 deletions

View file

@ -6,8 +6,8 @@
<script lang="ts">
import Vue from 'vue'
import {Theme} from '@/types/themes'
import {LIBRARY_ADDED, LIBRARY_CHANGED, LIBRARY_DELETED} from '@/types/events'
import {LibrarySseDto} from '@/types/komga-sse'
import {LIBRARY_ADDED, LIBRARY_CHANGED, LIBRARY_DELETED, SESSION_EXPIRED} from '@/types/events'
import {LibrarySseDto, SessionExpiredDto} from '@/types/komga-sse'
export default Vue.extend({
name: 'App',
@ -17,6 +17,8 @@ export default Vue.extend({
this.$eventHub.$on(LIBRARY_ADDED, this.reloadLibraries)
this.$eventHub.$on(LIBRARY_DELETED, this.reloadLibraries)
this.$eventHub.$on(LIBRARY_CHANGED, this.reloadLibraries)
this.$eventHub.$on(SESSION_EXPIRED, this.logout)
},
beforeDestroy() {
window.matchMedia('(prefers-color-scheme: dark)').removeEventListener('change', this.systemThemeChange)
@ -24,6 +26,8 @@ export default Vue.extend({
this.$eventHub.$off(LIBRARY_ADDED, this.reloadLibraries)
this.$eventHub.$off(LIBRARY_DELETED, this.reloadLibraries)
this.$eventHub.$off(LIBRARY_CHANGED, this.reloadLibraries)
this.$eventHub.$off(SESSION_EXPIRED, this.logout)
},
watch: {
'$store.state.persistedState.locale': {
@ -68,6 +72,10 @@ export default Vue.extend({
reloadLibraries(event: LibrarySseDto) {
this.$store.dispatch('getLibraries')
},
logout(event: SessionExpiredDto) {
this.$komgaUsers.logout()
this.$router.push({name: 'login'})
},
},
})
</script>

View file

@ -19,7 +19,7 @@ import {
READPROGRESS_SERIES_DELETED,
SERIES_ADDED,
SERIES_CHANGED,
SERIES_DELETED,
SERIES_DELETED, SESSION_EXPIRED,
THUMBNAILBOOK_ADDED,
THUMBNAILBOOK_DELETED,
THUMBNAILCOLLECTION_ADDED,
@ -101,6 +101,8 @@ export default class KomgaSseService {
this.eventSource.addEventListener('ThumbnailSeriesCollectionDeleted', (event: any) => this.emit(THUMBNAILCOLLECTION_DELETED, event))
this.eventSource.addEventListener('TaskQueueStatus', (event: any) => this.updateTaskCount(event))
this.eventSource.addEventListener('SessionExpired', (event: any) => this.emit(SESSION_EXPIRED, event))
}
disconnect() {

View file

@ -36,6 +36,8 @@ export const THUMBNAILREADLIST_DELETED = 'thumbnailreadlist-deleted'
export const THUMBNAILCOLLECTION_ADDED = 'thumbnailcollection-added'
export const THUMBNAILCOLLECTION_DELETED = 'thumbnailcollection-deleted'
export const SESSION_EXPIRED = 'session-expired'
export const ERROR = 'error'
export const NOTIFICATION = 'notification'

View file

@ -54,6 +54,10 @@ export interface ThumbnailCollectionSseDto {
selected: boolean,
}
export interface SessionExpiredDto {
userId: string,
}
export interface TaskQueueSseDto {
count: number,
countByType: { [key: string]: number }

View file

@ -18,6 +18,7 @@ import org.gotson.komga.interfaces.sse.dto.ReadListSseDto
import org.gotson.komga.interfaces.sse.dto.ReadProgressSeriesSseDto
import org.gotson.komga.interfaces.sse.dto.ReadProgressSseDto
import org.gotson.komga.interfaces.sse.dto.SeriesSseDto
import org.gotson.komga.interfaces.sse.dto.SessionExpiredDto
import org.gotson.komga.interfaces.sse.dto.TaskQueueSseDto
import org.gotson.komga.interfaces.sse.dto.ThumbnailBookSseDto
import org.gotson.komga.interfaces.sse.dto.ThumbnailReadListSseDto
@ -109,6 +110,9 @@ class SseController(
is DomainEvent.ThumbnailSeriesCollectionDeleted -> emitSse("ThumbnailSeriesCollectionDeleted", ThumbnailSeriesCollectionSseDto(event.thumbnail.collectionId, event.thumbnail.selected))
is DomainEvent.ThumbnailReadListAdded -> emitSse("ThumbnailReadListAdded", ThumbnailReadListSseDto(event.thumbnail.readListId, event.thumbnail.selected))
is DomainEvent.ThumbnailReadListDeleted -> emitSse("ThumbnailReadListDeleted", ThumbnailReadListSseDto(event.thumbnail.readListId, event.thumbnail.selected))
is DomainEvent.UserUpdated -> if (event.expireSession) emitSse("SessionExpired", SessionExpiredDto(event.user.id), userIdOnly = event.user.id)
is DomainEvent.UserDeleted -> emitSse("SessionExpired", SessionExpiredDto(event.user.id), userIdOnly = event.user.id)
}
}

View file

@ -0,0 +1,5 @@
package org.gotson.komga.interfaces.sse.dto
data class SessionExpiredDto(
val userId: String,
)