Browse Source

feat(gui-v2): check expiry in `signedIn` computed

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
pull/2716/head
Braks 2 years ago committed by Pranav C
parent
commit
b2c0f09d35
  1. 9
      packages/nc-gui-v2/composables/useGlobalState.ts

9
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<State>(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'] = () => {

Loading…
Cancel
Save