Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions packages/theme/src/cli/utilities/theme-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ import {hashString} from '@shopify/cli-kit/node/crypto'
import type {Writable} from 'stream'

vi.mock('@shopify/cli-kit/node/session')
vi.mock('@shopify/cli-kit/node/store-auth-session')
vi.mock('@shopify/cli-kit/node/store-auth-session', async (importOriginal) => {
const original = await importOriginal<typeof import('@shopify/cli-kit/node/store-auth-session')>()
return {
...original,
getCurrentStoredStoreAppSession: vi.fn(),
listCurrentStoredStoreAppSessions: vi.fn(),
}
})
vi.mock('@shopify/cli-kit/node/environments')
vi.mock('@shopify/cli-kit/node/ui')
vi.mock('@shopify/cli-kit/node/metadata', () => ({
Expand Down Expand Up @@ -395,15 +402,35 @@ describe('ThemeCommand', () => {
expect(command.commandCalls[0]).toMatchObject({session: mockSession})
})

test('does not check stored store auth cache session expiry', async () => {
test('falls back to theme authentication when the stored session is expired', async () => {
vi.mocked(getCurrentStoredStoreAppSession).mockReturnValue({
store: 'test-store.myshopify.com',
clientId: 'store-auth-client-id',
userId: 'preview:123',
accessToken: 'shpat_preview_token',
scopes: ['read_themes'],
acquiredAt: '2026-06-08T11:00:00.000Z',
expiresAt: new Date(Date.now() - 60 * 1000).toISOString(),
})

await CommandConfig.load()
const command = new TestScopedThemeCommand([], CommandConfig)

await command.run()

expect(ensureAuthenticatedThemes).toHaveBeenCalledWith('test-store.myshopify.com', undefined)
expect(command.commandCalls[0]).toMatchObject({session: mockSession})
})

test('uses a stored session whose expiry is far enough in the future', async () => {
vi.mocked(getCurrentStoredStoreAppSession).mockReturnValue({
store: 'test-store.myshopify.com',
clientId: 'store-auth-client-id',
userId: 'preview:123',
accessToken: 'shpat_preview_token',
scopes: ['read_themes'],
acquiredAt: '2026-06-08T11:00:00.000Z',
expiresAt: '2026-06-08T11:30:00.000Z',
expiresAt: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
})

await CommandConfig.load()
Expand Down
5 changes: 5 additions & 0 deletions packages/theme/src/cli/utilities/theme-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Command, {ArgOutput, FlagOutput, noDefaultsOptions} from '@shopify/cli-ki
import {AdminSession, ensureAuthenticatedThemes, setLastSeenUserId} from '@shopify/cli-kit/node/session'
import {
getCurrentStoredStoreAppSession,
isSessionExpired,
listCurrentStoredStoreAppSessions,
type StoredStoreAppSession,
} from '@shopify/cli-kit/node/store-auth-session'
Expand Down Expand Up @@ -421,6 +422,10 @@ export default abstract class ThemeCommand extends Command {
storeFqdn: string,
requiredScopes: string[],
): AdminSession | undefined {
if (isSessionExpired(storedSession)) {
return undefined
}
Comment thread
alfonso-noriega marked this conversation as resolved.

if (!this.hasRequiredStoreAuthScopes(storedSession.scopes, requiredScopes)) {
return undefined
}
Expand Down
Loading