diff --git a/composables/settings/storage.ts b/composables/settings/storage.ts index 917e398e..6c0395c5 100644 --- a/composables/settings/storage.ts +++ b/composables/settings/storage.ts @@ -2,10 +2,8 @@ import type { Ref } from 'vue' import type { FeatureFlags, UserSettings, WellnessSettings } from './definition' import { STORAGE_KEY_SETTINGS } from '~/constants' -export const useUserSettings = () => { - if (process.server) - return useState('user-settings', getDefaultUserSettings) - return useUserLocalStorage(STORAGE_KEY_SETTINGS, getDefaultUserSettings) +export function useUserSettings() { + return useUserLocalStorage(STORAGE_KEY_SETTINGS, getDefaultUserSettings) } // TODO: refactor & simplify this diff --git a/composables/users.ts b/composables/users.ts index ac010efb..71552295 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -277,7 +277,10 @@ interface UseUserLocalStorageCache { /** * Create reactive storage for the current user */ -export function useUserLocalStorage(key: string, initial: () => T) { +export function useUserLocalStorage(key: string, initial: () => T): Ref { + if (process.server) + return shallowRef(initial()) + // @ts-expect-error bind value to the function const map: Map = useUserLocalStorage._ = useUserLocalStorage._ || new Map() @@ -296,7 +299,7 @@ export function useUserLocalStorage(key: string, initial: () = map.set(key, { scope, value: value! }) } - return map.get(key)!.value + return map.get(key)!.value as Ref } /** diff --git a/layouts/default.vue b/layouts/default.vue index e72246ad..6897ffb9 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -13,7 +13,7 @@ const showUserPicker = logicAnd(