user-magnifying-glassUser & Subscriptions

Hooks for retrieving user identity, subscriptions, addresses, and payment methods in the Limio SDK.

In Limio Self-Service, authenticated users can view and manage their subscriptions through a self-service portal. The SDK provides hooks that retrieve real-time data about the current user, their subscriptions, addresses, and payment methods.

These hooks power pages like:

  • Account overview and profile display

  • Subscription management (upgrade, downgrade, cancel)

  • Contact details and address management

useUser()

Returns the authenticated user's identity, login status, and token.

import { useUser } from "@limio/sdk"

const user = useUser()

Returns:

Field
Type
Description

attributes

object

User profile attributes from the identity provider (email, name, custom claims)

loginStatus

"logged-in" | "logged-out"

Current authentication state

loaded

boolean

Always true once the hook resolves

token

string

The current session access token

Example — display the logged-in user's email:

import React from "react"
import { useUser } from "@limio/sdk"

const AccountHeader = () => {
  const { attributes, loginStatus } = useUser()

  if (loginStatus !== "logged-in") {
    return <p>Please sign in to view your account.</p>
  }

  return (
    <header>
      <p>Signed in as {attributes.email}</p>
    </header>
  )
}
chevron-rightExample user objecthashtag
circle-info

Custom claims (like crm_id above) come from your federated identity provider. See Authentication Integrationsarrow-up-right for setup.


getFederatedSignIn()

Triggers the federated sign-in flow, redirecting the user to the configured identity provider. Once authenticated, the user is redirected back to the originating page with an active session.

This is useful in components that need to programmatically initiate login — for example, gating an action behind authentication or building a custom sign-in button.

Returns: Promise<void> — triggers a full-page redirect; does not resolve in the current page context.

Example — require sign-in before a protected action:

Session expiry

Once signed in, the session token's expiry is available via useUser(). The attributes object includes standard JWT claims iat (issued at) and exp (expiry), both as Unix timestamps in seconds. Use these to determine session length or show time-remaining UI:

circle-info

getFederatedSignIn is typically called automatically by the Limio Authenticator when a page requires authentication. You only need to call it directly when building custom sign-in flows or gating specific actions behind authentication.


useSubscriptions()

Returns the list of subscriptions for the authenticated user.

Options:

Field
Type
Description

ownerId

string (optional)

Filter subscriptions by owner ID — used in B2B partner portals where one user manages multiple accounts

Example — list subscriptions with status:

Example — B2B partner portal with ownerId:

chevron-rightExample subscription objecthashtag

claimSubscriptionOwnership()

Transfers ownership of an anonymously-created subscription to the currently authenticated user. This is used when a subscriber completes a purchase without an account (guest checkout) and later signs in — calling this function links the existing subscription to their authenticated identity.

Parameters:

Param
Type
Description

subscriptionName

string

The subscription reference (e.g. "A-S00012345"). Max 64 alphanumeric chars, hyphens, and underscores.

Returns: Promise<{ id: string, name: string }>

Field
Type
Description

id

string

The subscription ID

name

string

The subscription reference passed in

Behaviour:

  • The authenticated user's email must match the email on the subscription's customer record (case-insensitive).

  • Only subscriptions owned by anonymous users (guest checkout) can be claimed. Subscriptions already owned by another authenticated user cannot be claimed.

  • Idempotent — calling it on a subscription the user already owns returns success without side effects.

  • On success, all related objects (orders, offers, add-ons, payment methods, addresses, schedules) are transferred to the authenticated user.

  • On failure, throws with HTTP 404 regardless of the reason (subscription not found, email mismatch, already claimed by another user).

circle-info

claimSubscriptionOwnership requires an authenticated session. The session token is used automatically.

Example — claim a subscription after sign-in:


Displaying subscription details

getCurrentOffer

Returns the current active offer from a subscription. Useful for showing the plan name and pricing on subscription management pages.

Reading schedule data

Each subscription includes a schedule array with past and future payment entries. To find the next upcoming payment, filter by date and status:

circle-info

formatDate and formatCurrency are exported from @limio/sdk and use the app's configured locale and date format.

useSubInfo

A convenience hook that extracts key metadata from a subscription object.

Returns:

Field
Type
Description

status

string

Current subscription status

isGift

boolean

Whether the subscription is a gift

quantity

number

Quantity on the subscription

hasLapsed

boolean | undefined

Whether the subscription has lapsed

hasPendingChange

boolean

Whether there is a scheduled change pending

useSchedule

A convenience hook that returns formatted schedule data for a subscription. Handles date formatting, currency formatting, and renewal price calculation.

Other subscription helpers

These helpers are available from @limio/sdk/subscription and @limio/sdk/offers:

Helper
Import
Description

getPeriodForOffer(offer)

@limio/sdk/offers

Returns the billing period string (e.g. "1 month") or "N/A" for one-off charges

checkCurrentSchedule(schedules)

@limio/sdk/subscription

Returns the next applicable schedule from an array

getRenewalDateForUserSubscription(sub)

@limio/sdk/subscription

Returns the formatted renewal date, or "N/A" if cancelled

getPriceForUserSubscription(sub)

@limio/sdk/subscription

Returns { value, currencyCode } for the next payment

getPriceFromSchedule(schedule, country?)

@limio/sdk/subscription

Extracts { value, currencyCode } from a schedule item


Addresses and payment methods

useLimioUserSubscriptionAddresses

Fetch billing and delivery addresses for a subscription. Returns an array of address objects with a revalidate function to refresh the data.

getCurrentAddress

Extract the active billing or delivery address from the addresses array.

Parameters:

Param
Type
Description

type

"billing" | "delivery"

The address type to retrieve

addresses

LimioAddressObject[]

The addresses array from useLimioUserSubscriptionAddresses

Example — display billing and delivery addresses:

chevron-rightExample address objecthashtag

useLimioUserSubscriptionPaymentMethods

Fetch stored payment methods for a subscription. Returns payment method details and a revalidate function.

The payment_methods array contains objects with card type, last four digits, and expiry information from the billing provider.


See also

Last updated

Was this helpful?