Shopify / cli

Build apps, themes, and hydrogen storefronts for Shopify
https://shopify.dev
MIT License
411 stars 125 forks source link

[Bug]: requests to Ajax Cart API fail with ERR_TOO_MANY_REDIRECTS #4449

Closed thelornenelson closed 22 hours ago

thelornenelson commented 1 week ago

Please confirm that you have:

In which of these areas are you experiencing a problem?

Theme

Expected behavior

Requests to the Cart AJAX Api should work as in preview themes, live themes, etc.

Actual behavior

When viewing local dev theme at 127.0.0.1 requests to the AJAX Cart API endpoints (likely all but at least /cart.js and /cart/update.js) fail with a net::ERR_TOO_MANY_REDIRECTS error.

For example, an initial request to /cart/update.js returns a 301 redirect to /cart/update.js?preview_theme_id=132860870729. A subsequent request to /cart/update.js?preview_theme_id=132860870729 returns another 301 redirect to the same url.

Image Image

This works properly on the old (non-dev preview), example: Image

Verbose output

This shows an auth problem due to the way I captured this log but there's no problem authenticating in normal usage.

2024-09-13T17:45:20.511Z: Running command theme dev
2024-09-13T17:45:20.517Z: Reading the content of file at shopify.theme.toml...
╭─ info ───────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  Using applicable flags from dev environment:                                │
│                                                                              │
│    • store: XXXXXX.myshopify.com                                     │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

2024-09-13T17:45:20.540Z: Ensuring that the user is authenticated with the Theme API with the following scopes:
[]

2024-09-13T17:45:20.540Z: Ensuring that the user is authenticated with the Admin API with the following scopes for the store XXXXXX.myshopify.com:
[]

2024-09-13T17:45:20.541Z: Getting session store...
2024-09-13T17:45:20.543Z: Validating existing session against the scopes:
[
  "openid",
  "https://api.shopify.com/auth/shop.admin.graphql",
  "https://api.shopify.com/auth/shop.admin.themes",
  "https://api.shopify.com/auth/partners.collaborator-relationships.readonly",
  "https://api.shopify.com/auth/shop.storefront-renderer.devtools",
  "https://api.shopify.com/auth/partners.app.cli.access",
  "https://api.shopify.com/auth/destinations.readonly"
]
For applications:
{
  "adminApi": {
    "scopes": [],
    "storeFqdn": "XXXXXX.myshopify.com"
  }
}

2024-09-13T17:45:20.543Z: Sending Identity Introspection request to URL: https://accounts.shopify.com/oauth/introspection
2024-09-13T17:45:20.543Z: Sending POST request to URL https://accounts.shopify.com/oauth/introspection
With request headers:
 - User-Agent: Shopify CLI; v=0.0.0-experimental-20240905102029
 - Keep-Alive: timeout=30
 - Sec-CH-UA-PLATFORM: darwin
 - Content-Type: application/json

2024-09-13T17:45:20.820Z: Request to https://accounts.shopify.com/oauth/introspection completed in 276 ms
With response headers:
 - cache-control: no-cache
 - content-type: text/html
 - server-timing: processing;dur=10, socket_queue;dur=1.455, edge;dur=1.024, util;dur=0.05, cfRequestDuration;dur=224.999905
 - x-request-id: 5e1468ef-10e1-4060-a5b1-f14b2a77ce07-1726249520

2024-09-13T17:45:20.820Z: The Introspection request failed with:
 - status: 401
 - www-authenticate header: "error=\"invalid_token\",error_description=\"The access token provided is expired, revoked, malformed or invalid for other reasons.\""
 - body: ""
2024-09-13T17:45:20.821Z: 
The validation of the token for application/identity completed with the following results:
- It's expired: false
- It's invalid in identity: true

2024-09-13T17:45:20.821Z: Initiating the full authentication flow...
2024-09-13T17:45:20.821Z: Requesting device authorization code...
2024-09-13T17:45:20.821Z: Sending POST request to URL https://accounts.shopify.com/oauth/device_authorization
With request headers:
 - User-Agent: Shopify CLI; v=0.0.0-experimental-20240905102029
 - Keep-Alive: timeout=30
 - Sec-CH-UA-PLATFORM: darwin
 - Content-Type: application/json
 - Content-type: application/x-www-form-urlencoded

2024-09-13T17:45:21.347Z: Request to https://accounts.shopify.com/oauth/device_authorization completed in 526 ms
With response headers:
 - cache-control: no-cache, no-store, private, must-revalidate, max-age=0
 - content-type: application/json; charset=utf-8
 - etag: W/"72402344277e6aec5c0e8e804c06678f"
 - server-timing: processing;dur=70, socket_queue;dur=1.969, edge;dur=0.016, util;dur=0.35, cfRequestDuration;dur=401.000023
 - x-request-id: c5168711-8343-4b38-87f3-0b80a91475ac-1726249520

2024-09-13T17:45:21.349Z: Received device authorization code: {
  "verification_uri": "https://shopify.com/activate",
  "verification_uri_complete": "https://accounts.shopify.com/activate-with-code?device_code%5Buser_code%5D=CDRB-HGQT",
  "expires_in": 600,
  "interval": 5,
  "device_code": "e96e9c7f-654a-4615-b5a9-50e67b46ab0e",
  "user_code": "CDRB-HGQT"
}

To run this command, log in to Shopify.
2024-09-13T17:45:21.364Z: 
Running system process:
  · Command: npm prefix
  · Working directory: /Users/andrewbarclay/Documents/Sweden/XXXXXX

2024-09-13T17:45:21.655Z: Obtaining the dependency manager in directory /Users/andrewbarclay/Documents/Sweden/XXXXXX...
2024-09-13T17:45:21.837Z: 
Running system process:
  · Command: ruby -v
  · Working directory: /Users/andrewbarclay/Documents/Sweden/XXXXXX

2024-09-13T17:45:22.183Z: Request to https://monorail-edge.shopifysvc.com/v1/produce completed in 214 ms
With response headers:
 - x-request-id: c1dfb2af-edf3-40e4-acfc-4fdbb2aa95ba

2024-09-13T17:45:22.183Z: Analytics event sent: {
  "command": "theme dev",
  "time_start": 1726249520512,
  "time_end": 1726249521357,
  "total_time": 845,
  "success": false,
  "cli_version": "0.0.0-experimental-20240905102029",
  "ruby_version": "2.7.5",
  "node_version": "20.11.1",
  "is_employee": false,
  "uname": "darwin arm64",
  "env_ci": false,
  "env_plugin_installed_any_custom": false,
  "env_plugin_installed_shopify": "[\"@shopify/cli\"]",
  "env_shell": "zsh",
  "env_device_id": "37e608a42d3cb7a6ebc0ab89b73037dfb6819c7f",
  "env_cloud": "localhost",
  "env_package_manager": "yarn",
  "env_is_global": true,
  "cmd_app_warning_api_key_deprecation_displayed": false,
  "cmd_all_timing_network_ms": 802,
  "cmd_all_timing_prompts_ms": 0,
  "cmd_all_launcher": "unknown",
  "cmd_all_topic": "theme",
  "cmd_all_plugin": "@shopify/theme",
  "cmd_all_force": false,
  "cmd_all_verbose": true,
  "cmd_all_path_override": true,
  "cmd_all_path_override_hash": "feaa1e090ab9576e0788b26ec89c2bda7507df56",
  "cmd_all_timing_active_ms": 42,
  "cmd_all_exit": "expected_error",
  "args": "--environment dev --dev-preview --verbose",
  "cmd_all_environment_flags": "{\"store\":\"XXXXXX\"}",
  "error_message": "Authorization is required to continue, but the current environment does not support interactive prompts.",
  "env_plugin_installed_all": "[\"@shopify/cli\"]",
  "metadata": "{\"extraPublic\":{},\"extraSensitive\":{}}"
}
2024-09-13T17:45:22.198Z: Reporting handled error to Bugsnag: Authorization is required to continue, but the current environment does not support interactive prompts.
2024-09-13T17:45:22.396Z: 
Running system process:
  · Command: npm prefix
  · Working directory: /Users/andrewbarclay/Documents/Sweden/XXXXXX

2024-09-13T17:45:22.579Z: Obtaining the dependency manager in directory /Users/andrewbarclay/Documents/Sweden/XXXXXX...

Reproduction steps

  1. Open theme for local dev with shopify theme dev -- --dev-preview
  2. View theme at 127.0.0.1
  3. Open console and attempt a request by typing fetch('cart.js') and pressing enter
  4. You should see an error similar to GET http://127.0.0.1:9292/products/cart.js?preview_theme_id=132860870729 net::ERR_TOO_MANY_REDIRECTS

Operating System

MacOS Sonoma 14.5

Shopify CLI version (check your project's package.json if you're not sure)

@shopify/cli/0.0.0-experimental-20240905102029

Shell

zsh

Node version (run node -v if you're not sure)

v20.11.1

What language and version are you using in your application?

No response

thelornenelson commented 22 hours ago

This seems to be resolved in the final 3.67.0 release so I'm going to close this issue. Thanks CLI team!