Skip to main content

useCurrentUser

The useCurrentUser hook allows you to fetch the profile information of the currently authenticated user. This is useful for building custom account pages or displaying personalized content.

Import

import { useCurrentUser } from '@appmaker-xyz/shopify';

Basic Usage

const { data: user, isLoading } = useCurrentUser({});

if (isLoading) return <LoadingSpinner />;

return (
<View>
<Text>Welcome back, {user?.firstName}!</Text>
<Text>Email: {user?.email}</Text>
</View>
);

Using Metafields

You can fetch specific Shopify customer metafields by passing an array to the hook.

const { data: user } = useCurrentUser({
metafields: [
{ namespace: "custom", key: "loyalty_points" },
{ namespace: "appmaker", key: "membership_type" }
]
});

// Accessing the retrieved metafields
const loyaltyPoints = user?.metafields?.find(
m => m.namespace === "custom" && m.key === "loyalty_points"
)?.value;

Hook API

Parameters

ParameterTypeDescription
metafieldsArray<{ namespace: string, key: string }>Optional. List of Shopify metafield identifiers to fetch.

Return Value

PropertyTypeDescription
dataObjectThe user object containing firstName, email, tags, phone, metafields, etc.
isLoadingbooleanIndicates if the request is in progress.
isSuccessbooleanTrue if the data was fetched successfully.
isErrorbooleanTrue if the fetch request failed.
erroranyError details if isError is true.