Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh session when 401 errors happens #4790

Merged
merged 4 commits into from
Nov 11, 2024
Merged

Refresh session when 401 errors happens #4790

merged 4 commits into from
Nov 11, 2024

Conversation

karreiro
Copy link
Contributor

@karreiro karreiro commented Nov 4, 2024

WHY are these changes introduced?

Fixes #4618

The Assets API may return 401 statuses after running for a while, and that may happen before the session gets refreshed. To prevent the development server from terminating, if we get that status, we manually refresh the session.

WHAT is this pull request doing?

This PR solves this by calling session.refresh() when it gets a 401 error. We'd face a circular dependency if we were to get the types correctly, so this PR checks the refresh at runtime and just calls it (this will no longer be necessary with #4769 solved).

How to test your changes?

  • Update the SESSION_TIMEOUT_IN_MS value (in dev-server-session.ts) to 300 * 60 * 1000
  • Run shopify theme dev --verbose
  • Leave a bash script appending a value in the sections/announcement-bar.liquid every 5 seconds
  • Notice that the session will get refreshed after a while (max wait time: ~2h)
  • Here's my results (in my test, I added some extra console.log logs to make things a bit clearer)

Post-release steps

N/A

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

github-actions bot commented Nov 4, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.12% (+0.08% 🔼)
8390/11633
🟡 Branches
68.56% (+0.06% 🔼)
4059/5920
🟡 Functions
71.43% (+0.06% 🔼)
2198/3077
🟡 Lines
72.53% (+0.08% 🔼)
7935/10941

Test suite run success

1901 tests passing in 867 suites.

Report generated by 🧪jest coverage report action from 45e9fa7

@karreiro karreiro marked this pull request as ready for review November 6, 2024 09:58
@karreiro karreiro requested review from a team as code owners November 6, 2024 09:58
@karreiro karreiro requested a review from jamesmengo November 6, 2024 09:58
Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, I think this is the right approach, refreshing on demand 🎉

It would be great if we could disallow destructuring the session object somehow... but I'm not sure if we can do that in JS 🤔

this will no longer be necessary with #4769 solved).

Nice!

@frandiox
Copy link
Contributor

frandiox commented Nov 6, 2024

/snapit

Copy link
Contributor

github-actions bot commented Nov 6, 2024

🫰✨ Thanks @frandiox! Your snapshot has been published to npm.

Test the snapshot by intalling your package globally:

pnpm i -g @shopify/[email protected]

After installing, validate the version by running just shopify in your terminal
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

.changeset/dull-shoes-clean.md Outdated Show resolved Hide resolved
@karreiro
Copy link
Contributor Author

karreiro commented Nov 8, 2024

@Shopify/app-inner-loop Could you please take a look at this one to unblock merge? 🙇

@karreiro karreiro enabled auto-merge November 8, 2024 17:00
@karreiro karreiro disabled auto-merge November 11, 2024 08:21
@karreiro
Copy link
Contributor Author

(I just rebased the branch because it got a conflict — it's ready to merge again)

@karreiro karreiro added this pull request to the merge queue Nov 11, 2024
Merged via the queue into main with commit 0572f93 Nov 11, 2024
27 checks passed
@karreiro karreiro deleted the 401-errors branch November 11, 2024 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Shopify CLI quits 'Dev' command intermittently
5 participants