|
|
@ -1,5 +1,6 @@ |
|
|
|
import { usePreferredDark, usePreferredLanguages, useStorage } from '@vueuse/core' |
|
|
|
import { usePreferredDark, usePreferredLanguages, useStorage } from '@vueuse/core' |
|
|
|
import { navigateTo } from '#app' |
|
|
|
import { navigateTo } from '#app' |
|
|
|
|
|
|
|
import { useJwt } from '@vueuse/integrations/useJwt' |
|
|
|
import { computed, toRefs } from '#build/imports' |
|
|
|
import { computed, toRefs } from '#build/imports' |
|
|
|
import type { Actions, Getters, GlobalState, State } from '~/lib/types' |
|
|
|
import type { Actions, Getters, GlobalState, State } from '~/lib/types' |
|
|
|
|
|
|
|
|
|
|
@ -18,10 +19,12 @@ export const useGlobalState = (): GlobalState => { |
|
|
|
|
|
|
|
|
|
|
|
const storage = useStorage<State>(storageKey, initialState) |
|
|
|
const storage = useStorage<State>(storageKey, initialState) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const token = $ref(storage.value.token) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { payload } = useJwt(token!) |
|
|
|
|
|
|
|
|
|
|
|
// getters
|
|
|
|
// getters
|
|
|
|
const signedIn: Getters['signedIn'] = computed( |
|
|
|
const signedIn: Getters['signedIn'] = computed(() => !!(!!token && payload.value && payload.value.exp && payload.value.exp > Date.now() / 1000)) |
|
|
|
() => storage.value.token !== null && storage.value.token !== '' && storage.value.user !== null, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// actions
|
|
|
|
// actions
|
|
|
|
const signOut: Actions['signOut'] = () => { |
|
|
|
const signOut: Actions['signOut'] = () => { |
|
|
|