Skip to content

Commit edad5b2

Browse files
committed
fix: the core config is not loaded on error pages
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent ed717d3 commit edad5b2

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

core/src/session-heartbeat.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ interface OcJsConfig {
1919
session_lifetime: number
2020
}
2121

22+
// This is always set, exception would be e.g. error pages where this is undefined
2223
const {
2324
auto_logout: autoLogout,
2425
session_keepalive: keepSessionAlive,
2526
session_lifetime: seesionLifetime,
26-
} = loadState<OcJsConfig>('core', 'config')
27+
} = loadState<Partial<OcJsConfig>>('core', 'config', {})
2728

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

146147
let intervalId = 0
147148
const logoutCheck = () => {
148-
const timeout = Date.now() - seesionLifetime * 1000
149+
const timeout = Date.now() - (seesionLifetime ?? 86400) * 1000
149150
if (lastActive < timeout) {
150151
clearTimeout(intervalId)
151152
logger.info('Inactivity timout reached, logging out')

core/src/tests/OC/session-heartbeat.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Session heartbeat', () => {
3535
initSessionHeartBeat()
3636

3737
// initial state loaded
38-
expect(initialState.loadState).toBeCalledWith('core', 'config')
38+
expect(initialState.loadState).toBeCalledWith('core', 'config', {})
3939

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

6666
// initial state loaded
67-
expect(initialState.loadState).toBeCalledWith('core', 'config')
67+
expect(initialState.loadState).toBeCalledWith('core', 'config', {})
6868

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

8787
// initial state loaded
88-
expect(initialState.loadState).toBeCalledWith('core', 'config')
88+
expect(initialState.loadState).toBeCalledWith('core', 'config', {})
8989

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

112112
// initial state loaded
113-
expect(initialState.loadState).toBeCalledWith('core', 'config')
113+
expect(initialState.loadState).toBeCalledWith('core', 'config', {})
114114

115115
// 23 hours
116116
await vi.advanceTimersByTimeAsync(23 * 60 * 60 * 1000)

0 commit comments

Comments
 (0)