Skip to content

useSessionContext

useSessionContext

Composable for session management. SessionContext contain all related data like user, currency, country, shippingMethod, paymentMethod etc.

Types

ts
export function useSessionContext(
  newContext?: Schemas["SalesChannelContext"],
): UseSessionContextReturn

source code

ts
export type UseSessionContextReturn = {
  /**
   * Patches the context in order to use new language
   */
  setLanguage(language: Partial<Schemas["Language"]>): Promise<void>;
  /**
   * Patches the context in order to use new countryId
   *
   * @param {string} countryId
   */
  setCountry(countryId: string): Promise<void>;
  /**
   * current context's language
   */
  sessionContext: ComputedRef<Schemas["SalesChannelContext"] | undefined>;
  /**
   * Fetches the session context and assigns the result to the `sessionContext` property
   */
  refreshSessionContext(): Promise<void>;
  /**
   * current context's language
   */
  selectedShippingMethod: ComputedRef<Schemas["ShippingMethod"] | null>;
  /**
   * Patches the context in order to use new shipping method
   */
  setShippingMethod(
    shippingMethod: Partial<Schemas["ShippingMethod"]>,
  ): Promise<void>;
  /**
   * current context's payment method
   */
  selectedPaymentMethod: ComputedRef<Schemas["PaymentMethod"] | null>;
  /**
   * Patches the context in order to use new payment method
   */
  setPaymentMethod(paymentMethod: { id: string }): Promise<void>;
  /**
   * current context's currency
   */
  currency: ComputedRef<Schemas["Currency"] | null>;
  /**
   * Patches the context in order to use new currency
   */
  setCurrency(currency: Partial<Schemas["Currency"]>): Promise<void>;
  /**
   * current context's shipping address
   */
  activeShippingAddress: ComputedRef<Schemas["CustomerAddress"] | null>;
  /**
   * Patches the context in order to use new shipping address
   */
  setActiveShippingAddress(
    address: Partial<Schemas["CustomerAddress"]>,
  ): Promise<void>;
  /**
   * current context's billing address
   */
  activeBillingAddress: ComputedRef<Schemas["CustomerAddress"] | null>;
  /**
   * current context's tax state
   */
  taxState: ComputedRef<string | undefined>;
  /**
   * Patches the context in order to use new billing address
   */
  setActiveBillingAddress(
    address: Partial<Schemas["CustomerAddress"]>,
  ): Promise<void>;
  /**
   * Patches the context with new context
   */
  setContext(context: Schemas["SalesChannelContext"]): void;
  /**
   * current context's country id
   */
  countryId: ComputedRef<string | undefined>;
  /**
   * current sales channel country id
   */
  salesChannelCountryId: ComputedRef<string | undefined>;
  /**
   * current language id
   */
  languageId: ComputedRef<string | undefined>;
  /**
   * current language id chain
   */
  languageIdChain: ComputedRef<string>;
  /**
   * current context's customer object
   */
  userFromContext: ComputedRef<Schemas["Customer"] | undefined>;
};

source code