From b2c0f09d3589de1375b5c29082ea8a593cf65773 Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Fri, 8 Jul 2022 09:31:27 +0200 Subject: [PATCH] feat(gui-v2): check expiry in `signedIn` computed Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com> --- packages/nc-gui-v2/composables/useGlobalState.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui-v2/composables/useGlobalState.ts b/packages/nc-gui-v2/composables/useGlobalState.ts index 37bbbb9f86..7626930134 100644 --- a/packages/nc-gui-v2/composables/useGlobalState.ts +++ b/packages/nc-gui-v2/composables/useGlobalState.ts @@ -1,5 +1,6 @@ import { usePreferredDark, usePreferredLanguages, useStorage } from '@vueuse/core' import { navigateTo } from '#app' +import { useJwt } from '@vueuse/integrations/useJwt' import { computed, toRefs } from '#build/imports' import type { Actions, Getters, GlobalState, State } from '~/lib/types' @@ -18,10 +19,12 @@ export const useGlobalState = (): GlobalState => { const storage = useStorage(storageKey, initialState) + const token = $ref(storage.value.token) + + const { payload } = useJwt(token!) + // getters - const signedIn: Getters['signedIn'] = computed( - () => storage.value.token !== null && storage.value.token !== '' && storage.value.user !== null, - ) + const signedIn: Getters['signedIn'] = computed(() => !!(!!token && payload.value && payload.value.exp && payload.value.exp > Date.now() / 1000)) // actions const signOut: Actions['signOut'] = () => {