--- title: Legacy customer account flow in Hydrogen description: Implement legacy customer account authentication using the Storefront API source_url: html: >- https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow md: >- https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md --- ExpandOn this page * [Requirements](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#requirements) * [Ingredients](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#ingredients) * [Step 1: Document legacy customer accounts in the README](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-1-document-legacy-customer-accounts-in-the-readme) * [Step 2: Add account link to header navigation](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-2-add-account-link-to-header-navigation) * [Step 3: Create account activation flow](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-3-create-account-activation-flow) * [Step 4: Update Page​Layout for legacy auth](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-4-update-pagelayout-for-legacy-auth) * [Step 5: Build password recovery flow](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-5-build-password-recovery-flow) * [Step 6: Validate customer access tokens](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-6-validate-customer-access-tokens) * [Step 7: Create customer registration flow](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-7-create-customer-registration-flow) * [Step 8: Handle unauthenticated account routes](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-8-handle-unauthenticated-account-routes) * [Step 9: Build password reset flow](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-9-build-password-reset-flow) * [Step 10: Add address management](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-10-add-address-management) * [Step 11: Show order details](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-11-show-order-details) * [Step 12: Display order history](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-12-display-order-history) * [Step 13: Build customer profile page](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-13-build-customer-profile-page) * [Step 14: Update account layout for session auth](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-14-update-account-layout-for-session-auth) * [Step 15: Create login page](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-15-create-login-page) * [Step 16: Handle logout and session cleanup](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#step-16-handle-logout-and-session-cleanup) * [Next steps](https://shopify.dev/docs/storefronts/headless/hydrogen/cookbook/legacy-customer-account-flow.md#next-steps) # Legacy customer account flow in Hydrogen This recipe converts a Hydrogen app from the new Customer Account API authentication to the legacy customer account flow using deprecated customer endpoints in Storefront API. This is useful for stores that haven't migrated to the new Customer Account API yet or need to maintain compatibility with existing customer authentication systems. Key features: * Full customer registration and login flow with form-based authentication * Password recovery and reset functionality via email * Account activation via email tokens * Customer profile management with editable fields * Order history with detailed order views * Address management (create, edit, delete, set default) * Session-based authentication using customer access tokens * Secure server-side rendering for all account routes Technical details: * Customer access tokens are stored in session cookies for authentication. * The login/register/recover routes use the account\_ prefix to avoid layout nesting. * Account data routes use the `account.` prefix to inherit the account layout Note Consider migrating to the new Customer Account API for better security and features. *** ## Requirements * A Shopify store with customer accounts enabled (classic accounts, not new customer accounts) * Storefront API access with customer read/write permissions * Email notifications configured in your Shopify admin for: * Account activation emails * Password reset emails * Welcome emails (optional) *** ## Ingredients *New files added to the template by this recipe.* | File | Description | | - | - | | [app/routes/account\_.activate.$id.$activationToken.tsx](https://github.com/Shopify/hydrogen/blob/12374c8f03f82c6800000cf08e327c4db4c287bb/cookbook/recipes/legacy-customer-account-flow/ingredients/templates/skeleton/app/routes/account_.activate.$id.$activationToken.tsx) | | | [app/routes/account\_.recover.tsx](https://github.com/Shopify/hydrogen/blob/12374c8f03f82c6800000cf08e327c4db4c287bb/cookbook/recipes/legacy-customer-account-flow/ingredients/templates/skeleton/app/routes/account_.recover.tsx) | | | [app/routes/account\_.register.tsx](https://github.com/Shopify/hydrogen/blob/12374c8f03f82c6800000cf08e327c4db4c287bb/cookbook/recipes/legacy-customer-account-flow/ingredients/templates/skeleton/app/routes/account_.register.tsx) | | | [app/routes/account\_.reset.$id.$resetToken.tsx](https://github.com/Shopify/hydrogen/blob/12374c8f03f82c6800000cf08e327c4db4c287bb/cookbook/recipes/legacy-customer-account-flow/ingredients/templates/skeleton/app/routes/account_.reset.$id.$resetToken.tsx) | | *** ## Step 1: Document legacy customer accounts in the README Update the README file to document the legacy customer account flow. #### File: [README.md](https://github.com/Shopify/hydrogen/blob/12374c8f03f82c6800000cf08e327c4db4c287bb/templates/skeleton/README.md) ([patch](https://github.com/Shopify/hydrogen/blob/12374c8f03f82c6800000cf08e327c4db4c287bb/cookbook/recipes/legacy-customer-account-flow/patches/README.md.db10ed.patch)) ```diff @@ -1,10 +1,26 @@ -# Hydrogen template: Skeleton +# Hydrogen template: Skeleton with Legacy Customer Account Flow -Hydrogen is Shopify’s stack for headless commerce. Hydrogen is designed to dovetail with [Remix](https://remix.run/), Shopify’s full stack web framework. This template contains a **minimal setup** of components, queries and tooling to get started with Hydrogen. +Hydrogen is Shopify's stack for headless commerce. Hydrogen is designed to dovetail with [Remix](https://remix.run/), Shopify's full stack web framework. This template contains a **minimal setup** of components, queries and tooling to get started with Hydrogen, enhanced with legacy customer account authentication flow. [Check out Hydrogen docs](https://shopify.dev/custom-storefronts/hydrogen) [Get familiar with Remix](https://remix.run/docs/en/v1) +## Legacy Customer Account Flow + +🚨 **Caution**: This legacy authentication strategy will not maintain authentication between your Hydrogen storefront and checkout; for better support, use either the New Customer Accounts strategy or Multipass. + +This template includes the legacy customer account flow made with [Storefront API](https://shopify.dev/docs/api/storefront) which provides: +- Full customer registration and login flow +- Password recovery and reset functionality +- Account activation via email +- Customer profile management +- Order history and address management +- Session-based authentication using customer access tokens + +**Note**: Passwordless login with [Customer Account API](https://shopify.dev/docs/api/customer) (introduced Jan 2024) is Shopify's recommended way to build headless customer experiences. Consider migrating to the new API for better security and features. + +🗒️ Read about the Customer Account API: [https://www.shopify.com/partners/blog/introducing-customer-account-api-for-headless-stores](https://www.shopify.com/partners/blog/introducing-customer-account-api-for-headless-stores) + ## What's included - Remix ``` *** ## Step 2: Add account link to header navigation Add an account link to the header navigation. #### File: [Header.tsx](https://github.com/Shopify/hydrogen/blob/12374c8f03f82c6800000cf08e327c4db4c287bb/templates/skeleton/app/components/Header.tsx) ([patch](https://github.com/Shopify/hydrogen/blob/12374c8f03f82c6800000cf08e327c4db4c287bb/cookbook/recipes/legacy-customer-account-flow/patches/Header.tsx.e25645.patch)) ```diff @@ -11,7 +11,8 @@ import {useAside} from '~/components/Aside'; interface HeaderProps { header: HeaderQuery; cart: Promise; - isLoggedIn: Promise; + // @description Use boolean instead of Promise for legacy authentication + isLoggedIn: boolean; publicStoreDomain: string; } @@ -103,11 +104,8 @@ function HeaderCtas({