> ## Documentation Index
> Fetch the complete documentation index at: https://weaverse.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Weaverse component configuration uses `settings`. `inspector` is deprecated; never generate it.
> Weaverse Hydrogen themes use React Router v7: import from `react-router`, never `react-router-dom` or `@remix-run/*`.
> Before using any code sample, read `@weaverse/hydrogen` in the project's `package.json`: 6.x and 5.x import from different entries and use different type names, so code for one does not build on the other.
> `@weaverse/hydrogen` 6 (Shopify Hydrogen 2026.10 and later, the version these docs show) imports from `@weaverse/hydrogen/react-router` and uses `Weaverse*` types such as `WeaverseComponentProps`, `WeaverseComponentLoaderArgs` and `WeaverseComponentSchema`; the root `@weaverse/hydrogen` entry only exports `createSchema()`, data helpers and types.
> `@weaverse/hydrogen` 5.x (Hydrogen 2026.4 and earlier) imports everything from `@weaverse/hydrogen` and uses `HydrogenComponentProps`, `ComponentLoaderArgs` and `HydrogenComponentSchema`. On a 5.x project, convert samples to these names. Upgrade to 6 only when asked (`npx @weaverse/cli@latest migrate v6`, plus the Hydrogen 2026.10 upgrade). Do not mix major versions.
> Next.js themes use `@weaverse/hydrogen` 6.2.0 or later: import client and shared code from `@weaverse/hydrogen/next` and server-only code from `@weaverse/hydrogen/next/server`. `@weaverse/next` is deprecated; never install or import it.
> For live project data (pages, theme settings, translations), use the Weaverse MCP server: https://weaverse.io/docs/developer-tools/weaverse-mcp

# Multipass in Hydrogen

> Implement Shopify Multipass SSO in a Hydrogen storefront using the legacy customer account flow and Storefront API customer access tokens.

# Multipass in Hydrogen

> [!NOTE]
>
> This guide is for Shopify Hydrogen storefronts. Building on Next.js? See the [Next.js overview](https://weaverse.io/docs/nextjs/overview.md).

Multipass lets a Shopify Plus merchant authenticate customers in an external system, then sign them into Shopify without asking for a Shopify password again. In Hydrogen, the recommended implementation is to exchange the Multipass token for a Storefront API `CustomerAccessToken`, store that access token in the Hydrogen session cookie, then use it for customer profile, order, address, and cart buyer identity calls.

> [!WARNING]
>
> Multipass is a **legacy customer accounts** feature. It does **not** work with Shopify's Customer Account API OAuth flow (`/account/login` → `/account/authorize`). If your storefront uses the Customer Account API routes from the Pilot theme, you must either keep that flow, or replace the account area with a legacy Storefront API customer-token flow.

## When to use Multipass

Use this guide when the merchant already has an external identity system, for example:

* A mobile app or loyalty app authenticates customers first
* An enterprise CRM validates customers by phone/OTP
* Middleware checks or creates the Shopify customer
* The middleware returns a Shopify Multipass token
* Hydrogen needs to complete login without sending the customer through Shopify's hosted login screen

Do **not** use Multipass for new builds unless the merchant has a hard legacy SSO requirement. Shopify's recommended path for new customer account implementations is the Customer Account API.

## Requirements

* Shopify Plus store
* **Legacy customer accounts** selected in **Shopify Admin → Settings → Customer accounts**
* Multipass enabled in Shopify admin
* Storefront API token with customer access-token permissions
* A server-side middleware or backend that generates Multipass tokens
* A Hydrogen storefront with cookie session support

> [!WARNING]
>
> Never generate a Multipass token in the browser. The Multipass secret must stay server-side.

## Architecture

```mermaid theme={null}
sequenceDiagram
  participant C as Customer
  participant H as Hydrogen storefront
  participant M as Merchant middleware / IdP
  participant S as Shopify Storefront API

  C->>H: Submit phone / OTP / external login
  H->>M: Validate customer
  M-->>H: Return Multipass token
  H->>S: customerAccessTokenCreateWithMultipass(token)
  S-->>H: CustomerAccessToken { accessToken, expiresAt }
  H->>H: Store customerAccessToken in session cookie
  H-->>C: Redirect to /account
  H->>S: Query customer(customerAccessToken)
```

The Multipass token is only an exchange credential. Hydrogen should store the returned `customerAccessToken`, not the Multipass token.

## Multipass token rules

Shopify's Storefront API mutation has two important constraints:

* Multipass tokens are valid for **15 minutes**
* Multipass tokens are **single-use**

Generate a fresh token on demand when a customer logs in. Do not pre-generate tokens, reuse tokens, or log them.

## Step 1 — Exchange Multipass for a customer access token

Create a server-side route that receives the Multipass token and exchanges it with Shopify.

The samples target Hydrogen 2026.10: Storefront API documents are `gql()` documents run with `context.storefront.graphql()`, and the session is Pilot's `AppSession` (`getSessionItem`, `setSessionItem`, `removeSessionItem`), which `server.ts` commits on every response. See the [v6 migration guide](https://weaverse.io/docs/migration-advanced/v6-migration.md#step-4-build-the-app-context-yourself) for both.

Example route: `app/routes/account/multipass.tsx`

```ts theme={null}
import {gql} from '@shopify/hydrogen';
import {redirect, type ActionFunctionArgs} from 'react-router';

const CUSTOMER_ACCESS_TOKEN_CREATE_WITH_MULTIPASS = gql(`
  mutation customerAccessTokenCreateWithMultipass($multipassToken: String!) {
    customerAccessTokenCreateWithMultipass(multipassToken: $multipassToken) {
      customerAccessToken {
        accessToken
        expiresAt
      }
      customerUserErrors {
        code
        field
        message
      }
    }
  }
`);

export async function action({request, context}: ActionFunctionArgs) {
  const formData = await request.formData();
  const multipassToken = String(formData.get('multipassToken') || '');

  if (!multipassToken) {
    throw new Response('Missing Multipass token', {status: 400});
  }

  const {data, errors: graphqlErrors} = await context.storefront.graphql(
    CUSTOMER_ACCESS_TOKEN_CREATE_WITH_MULTIPASS,
    {variables: {multipassToken}},
  );

  if (graphqlErrors?.length) {
    throw new Response('Unable to exchange Multipass token', {status: 502});
  }

  const customerAccessTokenCreateWithMultipass =
    data?.customerAccessTokenCreateWithMultipass;
  const errors =
    customerAccessTokenCreateWithMultipass?.customerUserErrors || [];

  if (errors.length) {
    throw new Response(errors[0].message, {status: 400});
  }

  const customerAccessToken =
    customerAccessTokenCreateWithMultipass?.customerAccessToken;

  if (!customerAccessToken?.accessToken) {
    throw new Response('Unable to create customer access token', {
      status: 400,
    });
  }

  // `server.ts` commits the session, so the redirect carries the cookie
  context.session.setSessionItem('customerAccessToken', {
    accessToken: customerAccessToken.accessToken,
    expiresAt: customerAccessToken.expiresAt,
  });

  return redirect('/account');
}
```

> [!NOTE]
>
> You can use a `loader` instead of an `action` if your external system redirects to Hydrogen with a token in the URL. Prefer `POST` when possible so tokens are not stored in browser history, server logs, analytics tools, or referer headers.

## Step 2 — Read the token from the Hydrogen session

In legacy customer account routes, read the stored token from `context.session`.

```ts theme={null}
import {Cache, gql} from '@shopify/hydrogen';
import {redirect, type LoaderFunctionArgs} from 'react-router';

const CUSTOMER_QUERY = gql(`
  query Customer($customerAccessToken: String!) {
    customer(customerAccessToken: $customerAccessToken) {
      id
      email
      firstName
      lastName
      phone
      orders(first: 10, sortKey: PROCESSED_AT, reverse: true) {
        nodes {
          id
          name
          processedAt
          totalPrice {
            amount
            currencyCode
          }
        }
      }
    }
  }
`);

export async function loader({context}: LoaderFunctionArgs) {
  const token = context.session.getSessionItem('customerAccessToken');

  if (!token?.accessToken) {
    return redirect('/account/login');
  }

  const {data, errors} = await context.storefront.graphql(CUSTOMER_QUERY, {
    variables: {
      customerAccessToken: token.accessToken,
    },
    cache: Cache.none(),
  });
  const customer = data?.customer;

  if (errors?.length || !customer) {
    context.session.removeSessionItem('customerAccessToken');
    return redirect('/account/login');
  }

  return {customer};
}
```

## Step 3 — Associate the customer with the cart

After login, the cart's buyer identity needs the Storefront API customer token. Hydrogen 2026.10 has no `context.cart`: the cart is served by Hydrogen's cart handlers at `/api/cart`. Pilot's own `POST /api/cart` handler (`createPilotCartHandlers` in `app/.server/cart.ts`) already runs `cartBuyerIdentityUpdate` with a customer access token before every cart change. Point its `getCustomerAccessToken` at the session's Multipass-derived token in `server.ts`:

```ts theme={null}
createPilotCartHandlers({
  getCustomerAccessToken: async () =>
    session.getSessionItem('customerAccessToken')?.accessToken,
}),
```

This helps Shopify associate the cart and checkout with the authenticated customer.

## Step 4 — Logout

Unset the customer access token from the Hydrogen session. If your merchant identity provider also has a session, redirect to its logout endpoint too.

```ts theme={null}
import {redirect, type ActionFunctionArgs} from 'react-router';

export async function action({context}: ActionFunctionArgs) {
  context.session.removeSessionItem('customerAccessToken');

  return redirect('/');
}
```

## Adapting the Pilot theme

The Pilot theme ships with Customer Account API routes by default:

* `/account/login` starts Shopify's Customer Account API OAuth flow (Hydrogen's Customer Account handlers, registered in `server.ts`)
* `/account/authorize` completes the OAuth callback
* Account pages query `context.customerAccount`

For Multipass, this is a different auth model. You need to replace or fork the account routes so they use:

* `context.storefront.graphql()` with `customerAccessTokenCreateWithMultipass` for login
* `context.session.getSessionItem('customerAccessToken')` for session state
* Storefront API `customer(customerAccessToken: ...)` queries for profile, orders, and addresses
* The session's token in Pilot's `POST /api/cart` handler for cart association

> [!WARNING]
>
> Do not try to pass a Multipass token to `/account/authorize`. That path is only the OAuth callback for Shopify's Customer Account API and is not a token-ingestion endpoint.

## Domain setup

Multipass does not have a callback-domain setup like Customer Account API OAuth. The domain depends on the implementation:

### Standard Shopify Multipass redirect

Redirect to the Shopify Online Store / classic account domain:

```txt theme={null}
https://{shop-domain}/account/login/multipass/{multipass_token}
```

Use this when the Liquid/Online Store customer-account session is the destination.

### Hydrogen-native Multipass exchange

Redirect or post to your Hydrogen route:

```txt theme={null}
https://www.example.com/account/multipass
```

Hydrogen exchanges the token with `customerAccessTokenCreateWithMultipass` and sets its own session cookie.

> [!NOTE]
>
> If Liquid and Hydrogen run in parallel, use separate domain targets in Shopify: for example `www.example.com` for Hydrogen and `checkout.example.com` or `liquid.example.com` for Online Store. Checkout remains Shopify checkout either way.

## Security checklist

* Keep the Multipass secret only in the merchant backend
* Generate Multipass tokens on demand
* Send tokens to Hydrogen server-side or via short-lived POST only
* Never store the Multipass token in the session
* Store only the returned `customerAccessToken`
* Use `httpOnly`, `sameSite: 'lax'`, and secure session cookies in production
* Use `Cache.none()` for authenticated customer/account queries
* Clear the session when the token is expired or customer lookup fails
* Avoid logging tokens, request bodies, query strings, or GraphQL variables that contain credentials

## Troubleshooting

> [accordion] `customerAccessTokenCreateWithMultipass` returns an error
>
> Confirm that Multipass is enabled, the store is on Shopify Plus, the store uses legacy customer accounts, and the token was generated with the correct Multipass secret. Also confirm that the token has not expired or already been used.

> [accordion] Customer logs in but account page still redirects to Shopify login
>
> The route is probably still using `context.customerAccount.handleAuthStatus()` or `context.customerAccount.query()`. Multipass requires legacy Storefront API customer-token queries instead.

> [accordion] Orders or profile data are empty
>
> Check that you are querying Storefront API customer fields with `customer(customerAccessToken: ...)`, not Customer Account API fields. Also verify the Multipass token uses the same email address as the Shopify customer record.

> [accordion] Checkout is not associated with the logged-in customer
>
> Run `cartBuyerIdentityUpdate` with the customer access token after login or before checkout, for example through Pilot's `POST /api/cart` handler as in Step 3. Use the returned Storefront API customer access token, not the Multipass token.

> [accordion] Customer Account API and Multipass both need to work
>
> Treat this as a custom dual-auth project. The two systems use different session models and account APIs. In most cases, the cleaner approach is to move existing customers into one IdP path using the same email address, or use a pure legacy customer-token flow if Multipass is mandatory.

## References

* [Shopify Multipass](https://shopify.dev/docs/api/customer-authentication/multipass)
* [Storefront API: customerAccessTokenCreateWithMultipass](https://shopify.dev/docs/api/storefront/latest/mutations/customerAccessTokenCreateWithMultipass)
* [Manage customer accounts with the Storefront API](https://shopify.dev/docs/storefronts/headless/building-with-the-storefront-api/customer-accounts)
* [Customer Account API with Hydrogen](https://shopify.dev/docs/storefronts/headless/building-with-the-customer-account-api/hydrogen)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.