fix: avoid requesting furiously if SESSION_DURATION is too low

Massimo Melina committed Apr 19, 2023 at 15:51 UTC edcc3ac83223337329406dd174e92a94b6547eb3
1 file changed +2 -1
frontend/src/login.ts
+2 -1
@@ -9,6 +9,7 @@ import { createElement as h, Fragment, useEffect, useRef } from 'react'
9 import { t, useI18N } from './i18n'
10 import { reloadList } from './useFetchList'
11 import { CustomCode } from './components'
12 +import _ from 'lodash'
13
14 async function login(username:string, password:string) {
15 const stopWorking = working()
@@ -36,7 +37,7 @@ function sessionRefresher(response: any) {
37 state.adminUrl = adminUrl
38 if (!username || !exp) return
39 const delta = new Date(exp).getTime() - Date.now()
39 - const t = Math.min(delta - 30_000, 600_000)
40 + const t = _.clamp(delta - 30_000, 5_000, 600_000)
41 console.debug('session refresh in', Math.round(t/1000))
42 setTimeout(() => apiCall('refresh_session').then(sessionRefresher), t)
43 }