Skip to content
Prev Previous commit
Next Next commit
fix: the core config is not loaded on error pages
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Jun 16, 2025
commit edad5b2229853ae5c052dd4c97fc921e51e3d144
5 changes: 3 additions & 2 deletions core/src/session-heartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ interface OcJsConfig {
session_lifetime: number
}

// This is always set, exception would be e.g. error pages where this is undefined
const {
auto_logout: autoLogout,
session_keepalive: keepSessionAlive,
session_lifetime: seesionLifetime,
} = loadState<OcJsConfig>('core', 'config')
} = loadState<Partial<OcJsConfig>>('core', 'config', {})

/**
* Calls the server periodically to ensure that session and CSRF
Expand Down Expand Up @@ -145,7 +146,7 @@ function registerAutoLogout() {

let intervalId = 0
const logoutCheck = () => {
const timeout = Date.now() - seesionLifetime * 1000
const timeout = Date.now() - (seesionLifetime ?? 86400) * 1000
if (lastActive < timeout) {
clearTimeout(intervalId)
logger.info('Inactivity timout reached, logging out')
Expand Down
8 changes: 4 additions & 4 deletions core/src/tests/OC/session-heartbeat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Session heartbeat', () => {
initSessionHeartBeat()

// initial state loaded
expect(initialState.loadState).toBeCalledWith('core', 'config')
expect(initialState.loadState).toBeCalledWith('core', 'config', {})

// less than half, still nothing
await vi.advanceTimersByTimeAsync(100 * 1000)
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('Session heartbeat', () => {
initSessionHeartBeat()

// initial state loaded
expect(initialState.loadState).toBeCalledWith('core', 'config')
expect(initialState.loadState).toBeCalledWith('core', 'config', {})

// less than half, still nothing
await vi.advanceTimersByTimeAsync(100 * 1000)
Expand All @@ -85,7 +85,7 @@ describe('Session heartbeat', () => {
initSessionHeartBeat()

// initial state loaded
expect(initialState.loadState).toBeCalledWith('core', 'config')
expect(initialState.loadState).toBeCalledWith('core', 'config', {})

// 30 / 55 seconds
await vi.advanceTimersByTimeAsync(30 * 1000)
Expand All @@ -110,7 +110,7 @@ describe('Session heartbeat', () => {
initSessionHeartBeat()

// initial state loaded
expect(initialState.loadState).toBeCalledWith('core', 'config')
expect(initialState.loadState).toBeCalledWith('core', 'config', {})

// 23 hours
await vi.advanceTimersByTimeAsync(23 * 60 * 60 * 1000)
Expand Down