Hydrogen with account component
Follow this guide to add the <shopify-account> component to your Hydrogen storefront, allowing customers to sign in and stay on the storefront, or navigate directly to customer account pages from the storefront.
Anchor to RequirementsRequirements
- Create a Hydrogen storefront and deploy to Oxygen by following this tutorial.
- You're familiar with storefront web components.
- You've completed Using the Customer Account API with Hydrogen.
Anchor to Step 1: Enable API permissionsStep 1: Enable API permissions
This requires setting the public-access-token attribute on your <shopify-store> component.
In your store's Shopify admin, open the Hydrogen app. Then select your Hydrogen storefront and navigate to Storefront settings > Storefront API.
Confirm that your Hydrogen app has the following Storefront API permissions:
unauthenticated_read_customersunauthenticated_read_contentunauthenticated_read_product_listings
Anchor to Step 2: Pass tokens to the account componentStep 2: Pass tokens to the account component
To use the <shopify-account> component, you must provide the following two tokens:
public-access-token: Retrieved fromPUBLIC_STOREFRONT_API_TOKENin your environment file.customer-access-token: See Using the Customer Account API with Hydrogen. After the customer is authenticated, pass the customer access token to thecustomer-access-tokenattribute. Be sure to update the application setup.
In /app/root.jsx, replace the loader function with the following implementation. This passes publicAccessToken and customerAccessToken to downstream components.
/app/root.jsx
In the /app/components/PageLayout.jsx file, replace PageLayout function as following code:
/app/components/PageLayout.jsx
Near the bottom of /app/components/PageLayout.jsx, you should see * @property {string} publicStoreDomain. Add the following property types:
/app/components/PageLayout.jsx
Anchor to Step 3: Load the account JavaScript bundle and add the account componentStep 3: Load the account Java Script bundle and add the account component
The <shopify-account> component bundle isn't included in the default Hydrogen storefront. Before using the component, be sure to load its dedicated bundle (https://cdn.shopify.com/storefront/web-components/account.js).
In /app/root.jsx, import Script from @shopify/hydrogen and add the following <Script> tag inside the <head> of the Layout component:
/app/root.jsx
In /app/components/Header.jsx, replace the Header function with the following code:
/app/components/Header.jsx
In the middle of /app/components/Header.jsx file, replace the HeaderCtas function with the code below so we can replace the default Sign In with the <shopify-account> component.
sign-in-url: The URL you provide in thesign-in-urlattribute should point to the page that initiates the authorization request. In Hydrogen, the default path is/account/login.
/app/components/Header.jsx
Near the bottom of /app/components/Header.jsx, you should see * @property {string} publicStoreDomain. Add the following property types:
/app/components/Header.jsx
You can style the <shopify-account> component to match your storefront. For details, please refer to this documentation.
Anchor to Step 4: Handle login URL parametersStep 4: Handle login URL parameters
As of version 2025.7.3 of @shopify/hydrogen, we've introduced additional options to improve the login experience. You can learn more here.
If your Hydrogen storefront was created recently, you don't have to do anything else.
If you're using @shopify/hydrogen earlier than 2025.7.3, upgrade to the latest version. Then update the loader function in /app/routes/account_.login.jsx as shown below.
/app/routes/account_.login.jsx
Anchor to Step 5: Deploy your code to production OxygenStep 5: Deploy your code to production Oxygen
The Customer Account API doesn't support localhost, so you'll need to deploy your code before testing this feature. Commit your changes and run the following command to deploy:
Terminal
After deployment, open your production Hydrogen storefront—you should see the account component present.