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
Consider migrating to the new Customer Account API for better security and features.
Consider migrating to the new Customer Account API for better security and features.
Anchor to RequirementsRequirements
- 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)
Anchor to IngredientsIngredients
New files added to the template by this recipe.
| File | Description |
|---|---|
| app/routes/account_.activate.$id.$activationToken.tsx | |
| app/routes/account_.recover.tsx | |
| app/routes/account_.register.tsx | |
| app/routes/account_.reset.$id.$resetToken.tsx |
Anchor to Step 1: Document legacy customer accounts in the READMEStep 1: Document legacy customer accounts in the README
Update the README file to document the legacy customer account flow.
Add an account link to the header navigation.
Anchor to Step 3: Create account activation flowStep 3: Create account activation flow
Add an account activation route for email verification.
File
Anchor to Step 4: Update PageLayout for legacy authStep 4: Update Page Layout for legacy auth
Update PageLayout to handle account routes.
Anchor to Step 5: Build password recovery flowStep 5: Build password recovery flow
Add a password recovery form.
File
Anchor to Step 6: Validate customer access tokensStep 6: Validate customer access tokens
Add customer access token validation to the root loader.
File
Anchor to Step 7: Create customer registration flowStep 7: Create customer registration flow
Add a customer registration form.
File
Anchor to Step 8: Handle unauthenticated account routesStep 8: Handle unauthenticated account routes
Convert the catch-all route to use Storefront API authentication.
Anchor to Step 9: Build password reset flowStep 9: Build password reset flow
Add a password reset form with token validation.
File
Anchor to Step 10: Add address managementStep 10: Add address management
Convert address management to use Storefront API mutations.
File
Anchor to Step 11: Show order detailsStep 11: Show order details
Convert the order details page to use Storefront API queries.
File
Anchor to Step 12: Display order historyStep 12: Display order history
Convert the orders list to use the Storefront API with pagination.
File
Anchor to Step 13: Build customer profile pageStep 13: Build customer profile page
Convert the customer profile page to use Storefront API queries.
File
Anchor to Step 14: Update account layout for session authStep 14: Update account layout for session auth
Convert the account layout to use session-based authentication.
File
Anchor to Step 15: Create login pageStep 15: Create login page
Replace the Customer Account API login with the Storefront API form.
File
Anchor to Step 16: Handle logout and session cleanupStep 16: Handle logout and session cleanup
Replace the Customer Account API logout with a session cleanup.
Anchor to Next stepsNext steps
After applying this recipe:
- Run
npm run codegento generate GraphQL types for the Storefront API queries. - Run
npm run devto start the development server. - Test the authentication flow:
- Visit
/account/registerto create a new account - Check your email for the activation link
- Visit
/account/loginto sign in - Browse
/account/ordersto view order history - Visit
/account/addressesto manage addresses
- Visit
- Configure email templates in your Shopify admin:
- Go to Settings > Notifications
- Customize the Customer account activation email
- Customize the Customer account password reset email
- Consider implementing:
- "Remember me" functionality with longer session expiry
- Social login integration
- Two-factor authentication
- Customer profile fields (phone, marketing preferences)