feat: fix calculation of token invalidation
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dominik Pschenitschni 2023-02-08 15:28:21 +01:00
parent a3a313a21f
commit bf957319f9
Signed by: dpschen
GPG Key ID: B257AC0149F43A77
1 changed files with 6 additions and 3 deletions

View File

@ -3,7 +3,7 @@ import {useRouter} from 'vue-router'
import {useEventListener} from '@vueuse/core'
import {useAuthStore} from '@/stores/auth'
import {MILLISECONDS_A_HOUR, SECONDS_A_HOUR} from '@/constants/date'
import {MILLISECONDS_A_SECOND, SECONDS_A_HOUR} from '@/constants/date'
const SECONDS_TOKEN_VALID = 60 * SECONDS_A_HOUR
@ -24,11 +24,14 @@ export function useRenewTokenOnFocus() {
return
}
const expiresIn = (userInfo.value !== null ? userInfo.value.exp : 0) - new Date().valueOf() / MILLISECONDS_A_HOUR
const nowInSeconds = new Date().getTime() / MILLISECONDS_A_SECOND
const expiresIn = userInfo.value !== null
? userInfo.value.exp - nowInSeconds
: 0
// If the token expiry is negative, it is already expired and we have no choice but to redirect
// the user to the login page
if (expiresIn < 0) {
if (expiresIn <= 0) {
await authStore.checkAuth()
await router.push({name: 'user.login'})
return