Shopify / Shopify/shopify-app-template-node

[Bug]: Unable to renew session

Open
#900 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Waiting for Response
Dominant language
JavaScript
Stars
1k
Forks
434
PR merge metrics
No merged PRs in 30d

Description

Moved from this issue
Originally reported by @marvinhagemeister

Please confirm that you have:
  • Searched existing issues to see if your issue is a duplicate. (If you’ve found a duplicate issue, feel free to add additional information in a comment on it.)
  • Reproduced the issue in the latest CLI version.
What type of project are you working on?

App

Expected behavior

I would have expected the CLI to automatically renew tokens.

Actual behavior

Just came back to my machine after lunch and noticed that my app isn't showing up anymore. Instead I get a gateway timeout error:

{"statusCode":504,"error":"Gateway Timeout","message":"Gateway Timeout"}

The error remains after refreshing the page. Checking the console it looks like the jwt token expired and the CLI doesn't seem to renew it.

Stack trace
frontend   | 10:24:31 AM [vite] page reload pages/index.jsx
backend    | ERROR /Users/marvinhagemeister/src/test/shopify-beta/test-app/web/node_modules/@shopify/shopify-api/dist/error.js:13
backend    | ERROR         var _this = _super.apply(this, tslib_1.__spreadArray([], tslib_1.__read(args), false)) || this;
backend    | ERROR                            ^
backend    | ERROR 
backend    | ERROR InvalidJwtError: Failed to parse session token 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczpcL1wvbWFydmluLWhhZ2VtZWlzdGVyLWJldGEtc3RvcmUubXlzaG9waWZ5LmNvbVwvYWRtaW4iLCJkZXN0IjoiaHR0cHM6XC9cL21hcnZpbi1oYWdlbWVpc3Rlci1iZXRhLXN0b3JlLm15c2hvcGlmeS5jb20iLCJhdWQiOiI0ZDMwMmQ1ZjY5NWRlYmRjMzQxNGQ0YzRmYTc3YjUwOSIsInN1YiI6Ijc4ODc2MzQ0Mzc2IiwiZXhwIjoxNjU0MTYxNjM1LCJuYmYiOjE2NTQxNjE1NzUsImlhdCI6MTY1NDE2MTU3NSwianRpIjoiMjlkMDUzZWUtYWViMC00M2RmLWJhNzMtZDA5MDg4MmFlMTg2Iiwic2lkIjoiNWExZGM1YzYyZmZjODZhYmY5ZmE4N2VmMGM0ZTVkMzExOTRlZjFiNGIyYjBlMmRiYzExMjc4ZTM0NWNhNDMzYiJ9.wKeGN-gQrEIBjZrf10sVWGYuu-f35DUHVMro7Qzsz04': jwt expired
backend    | ERROR     at InvalidJwtError.ShopifyError [as constructor] (/Users/marvinhagemeister/src/test/shopify-beta/test-app/web/node_modules/@shopify/shopify-api/dist/error.js:13:28)
backend    | ERROR     at new InvalidJwtError (/Users/marvinhagemeister/src/test/shopify-beta/test-app/web/node_modules/@shopify/shopify-api/dist/error.js:39:42)
backend    | ERROR     at decodeSessionToken (/Users/marvinhagemeister/src/test/shopify-beta/test-app/web/node_modules/@shopify/shopify-api/dist/utils/decode-session-token.js:23:15)
backend    | ERROR     at Object.getCurrentSessionId (/Users/marvinhagemeister/src/test/shopify-beta/test-app/web/node_modules/@shopify/shopify-api/dist/auth/oauth/oauth.js:211:69)
backend    | ERROR     at Object.<anonymous> (/Users/marvinhagemeister/src/test/shopify-beta/test-app/web/node_modules/@shopify/shopify-api/dist/utils/load-current-session.js:19:46)
backend    | ERROR     at step (/Users/marvinhagemeister/src/test/shopify-beta/test-app/web/node_modules/tslib/tslib.js:144:27)
backend    | ERROR     at Object.next (/Users/marvinhagemeister/src/test/shopify-beta/test-app/web/node_modules/tslib/tslib.js:125:57)
backend    | ERROR     at /Users/marvinhagemeister/src/test/shopify-beta/test-app/web/node_modules/tslib/tslib.js:118:75
backend    | ERROR     at new Promise (<anonymous>)
backend    | ERROR     at Object.__awaiter (/Users/marvinhagemeister/src/test/shopify-beta/test-app/web/node_modules/tslib/tslib.js:114:16)
backend    | ERROR 
backend    | ERROR Node.js v18.2.0
frontend   | ERROR 12:05:45 PM [vite] http proxy error:
frontend   | ERROR Error: read ECONNRESET
frontend   | ERROR     at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
frontend   | ERROR 12:05:45 PM [vite] http proxy error:
frontend   | ERROR Error: socket hang up
frontend   | ERROR     at connResetException (node:internal/errors:693:14)
frontend   | ERROR     at Socket.socketOnEnd (node:_http_client:478:23)
frontend   | ERROR     at Socket.emit (node:events:539:35)
frontend   | ERROR     at endReadableNT (node:internal/streams/readable:1344:12)
frontend   | ERROR     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
backend    | [nodemon] app crashed - waiting for file changes before starting...
frontend   | ERROR 12:15:50 PM [vite] http proxy error:
frontend   | ERROR Error: connect ECONNREFUSED 127.0.0.1:56160
frontend   | ERROR     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16)
frontend   | ERROR 12:17:12 PM [vite] http proxy error:
frontend   | ERROR Error: connect ECONNREFUSED 127.0.0.1:56160
frontend   | ERROR     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16)
Reproduction steps
  1. Create an app and register that in the store
  2. Wait until jwt is expired (not sure how long, was away for a bit more than an hour)
Operating System

macOS Monterey

Shopify CLI version (run shopify version if you're not sure)

3.0.4

Shell

zsh

Ruby version (run ruby -v if you're not sure)

No response

What language and version are you using in your application?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the session-token flow shown in the stack trace, especially getCurrentSessionId, load-current-session, and decodeSessionToken in the Shopify API package. Reproduce the failure by letting the JWT expire, then verify that an expired token no longer crashes the backend and that the app can recover as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, react
Domain
authentication, backend, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.