UNPKG

@scayle/storefront-nuxt

Version:

Nuxt integration for the SCAYLE Commerce Engine and Storefront API

43 lines (42 loc) 1.98 kB
import type { ShopUser, UpdatePasswordParams } from '@scayle/storefront-core'; import type { UseRpcReturn, UseRpcCacheKey } from './useRpc.js'; import type { ComputedRef } from 'vue'; /** * Extended parameters for the `useUser` composable. */ export interface ExtendedUseUserParams { /** The key used for caching the user data. Defaults to 'useUser'. */ key?: UseRpcCacheKey; /** Whether to fetch the user data immediately. Defaults to `true`. */ immediate?: boolean; /** Whether to enable lazy loading of user data. Defaults to `false`. */ lazy?: boolean; } type UseUserBaseReturn = Pick<Awaited<UseRpcReturn<'getUser'>>, 'error' | 'status' | 'refresh'> & { updateUser: (payload: Partial<ShopUser>) => Promise<void>; updatePassword: (payload: UpdatePasswordParams) => Promise<void>; user: ComputedRef<ShopUser | undefined>; isLoggedIn: ComputedRef<boolean>; customerType: ComputedRef<'new' | 'guest' | 'existing'>; forceRefresh: () => Promise<void>; }; /** * Provides user information and related actions. * * This composable retrieves user data via the `getUser` RPC method and offers * functionalities to update user details, change passwords, and force-refresh user data. * It uses `useRpc` for data fetching and provides computed properties for user status, * login status, and customer type. * * The composable also handles caching of user data and allows for lazy loading * and immediate fetching based on the provided options. * * @param options Options to customize the behavior of the composable, * such as caching key, immediate fetching, and lazy loading. * * @returns A promise that resolves to an object containing user information, * update functions, and status properties. It also includes the resolved * object directly as properties. */ export declare function useUser(options?: ExtendedUseUserParams): UseUserBaseReturn & Promise<UseUserBaseReturn>; export {};