Skip to content

Skip expired store auth sessions in theme commands - #8185

Merged
alfonso-noriega merged 1 commit into
mainfrom
theme-store-auth-skip-expired
Jul 29, 2026
Merged

Skip expired store auth sessions in theme commands#8185
alfonso-noriega merged 1 commit into
mainfrom
theme-store-auth-skip-expired

Conversation

@alfonso-noriega

@alfonso-noriega alfonso-noriega commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

Third layer of the theme dev store-auth regression fix (Slack thread); stacked on #8184.

Theme commands read stored store-auth sessions with the raw cache accessor and never checked expiry. An expired token was handed to the Admin API, and the resulting 401 was terminal: the theme session carries no refresh handler (adminRequestDoc only installs one when 'refresh' in session), and the failure path never falls back to normal authentication. This is the exact shape of the July 8 Enterprise case (401 on publicApiVersions that auth logout + re-auth couldn't fix).

WHAT is this pull request doing?

  • Skips stored sessions that fail cli-kit's isSessionExpired (including its 4-minute refresh margin) and falls back to normal theme authentication.
  • Flips the test that pinned the old behavior (does not check stored store auth cache session expiry) and adds a positive test for future expiries.
  • Switches the test file to a partial module mock so the real isSessionExpired implementation runs.

Actual token refresh (the refresh client lives in @shopify/store, which @shopify/theme deliberately no longer depends on) is left as follow-up work.

How to test your changes?

Covered by unit tests (theme-command.test.ts): a stored session with a past expiresAt is skipped and the command authenticates normally; a future expiresAt is still reused.

Measuring impact

  • Existing analytics will cater for this addition

alfonso-noriega commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Comment thread .changeset/theme-store-auth-skip-expired.md Outdated
Comment thread packages/theme/src/cli/utilities/theme-command.ts
Theme commands read stored store auth sessions with the raw cache
accessor and never checked expiry, so an expired token was handed to the
Admin API and the resulting 401 was terminal: the theme session carries
no refresh handler and the failure path never falls back to normal
authentication. Reuse isSessionExpired from cli-kit (including its
refresh margin) so expired sessions are skipped and the command
authenticates normally instead.

Assisted-By: devx/60503589-d48c-43b2-8fba-b0df1e076f15
@alfonso-noriega
alfonso-noriega force-pushed the theme-store-auth-require-recorded-scopes branch from b492a9f to ed332dd Compare July 29, 2026 09:33
@alfonso-noriega
alfonso-noriega force-pushed the theme-store-auth-skip-expired branch from 6abd257 to 7bb01a9 Compare July 29, 2026 09:33
@github-actions github-actions Bot added no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. and removed Area: @shopify/theme @shopify/theme package issues labels Jul 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/api/partners.d.ts
@@ -1,5 +1,7 @@
 import { GraphQLVariables, GraphQLResponse, CacheOptions, UnauthorizedHandler } from './graphql.js';
 import { RequestModeInput } from '../http.js';
+import { Variables } from 'graphql-request';
+import { TypedDocumentNode } from '@graphql-typed-document-node/core';
 /**
  * Executes a GraphQL query against the Partners API.
  *
@@ -12,6 +14,17 @@ import { RequestModeInput } from '../http.js';
  * @returns The response of the query of generic type <T>.
  */
 export declare function partnersRequest<T>(query: string, token: string, variables?: GraphQLVariables, cacheOptions?: CacheOptions, preferredBehaviour?: RequestModeInput, unauthorizedHandler?: UnauthorizedHandler): Promise<T>;
+/**
+ * Executes a GraphQL query against the Partners API. Uses typed documents.
+ *
+ * @param query - GraphQL query to execute.
+ * @param token - Partners token.
+ * @param variables - GraphQL variables to pass to the query.
+ * @param preferredBehaviour - Preferred behaviour for the request.
+ * @param unauthorizedHandler - Optional handler for unauthorized requests.
+ * @returns The response of the query of generic type <TResult>.
+ */
+export declare function partnersRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, preferredBehaviour?: RequestModeInput, unauthorizedHandler?: UnauthorizedHandler): Promise<TResult>;
 /**
  * Sets the next deprecation date from [GraphQL response extensions](https://www.apollographql.com/docs/resources/graphql-glossary/#extensions)
  * if `response.extensions.deprecations` objects contain a `supportedUntilDate` (ISO 8601-formatted string).

Base automatically changed from theme-store-auth-require-recorded-scopes to main July 29, 2026 14:27
@alfonso-noriega
alfonso-noriega added this pull request to the merge queue Jul 29, 2026
Merged via the queue into main with commit f42047b Jul 29, 2026
30 of 53 checks passed
@alfonso-noriega
alfonso-noriega deleted the theme-store-auth-skip-expired branch July 29, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants