Skip to content

Commit 2fbc81e

Browse files
committed
Authenticate theme push when used programmatically
CLI commands push and pull are exported publicly through @shopify/cli so external packages (like shopkeeper) can use them. When push is used programmatically we need to authenticate inside the function as we wont have access to the session created by ThemeCommand
1 parent b855ec1 commit 2fbc81e

File tree

1 file changed

+7
-2
lines changed
  • packages/theme/src/cli/services

1 file changed

+7
-2
lines changed

packages/theme/src/cli/services/push.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {findOrSelectTheme} from '../utilities/theme-selector.js'
77
import {Role} from '../utilities/theme-selector/fetch.js'
88
import {configureCLIEnvironment} from '../utilities/cli-config.js'
99
import {runThemeCheck} from '../commands/theme/check.js'
10-
import {AdminSession} from '@shopify/cli-kit/node/session'
10+
import {ensureThemeStore} from '../utilities/theme-store.js'
11+
import {AdminSession, ensureAuthenticatedThemes} from '@shopify/cli-kit/node/session'
1112
import {themeCreate, fetchChecksums, themePublish} from '@shopify/cli-kit/node/themes/api'
1213
import {Result, Theme} from '@shopify/cli-kit/node/themes/types'
1314
import {outputResult} from '@shopify/cli-kit/node/output'
@@ -122,6 +123,10 @@ export async function push(
122123
) {
123124
const environment = flags.environment?.[0]
124125

126+
// when push is used programmatically, we don't have an admin session, so need to create one
127+
const session =
128+
adminSession ?? (await ensureAuthenticatedThemes(ensureThemeStore({store: flags.store}), flags.password))
129+
125130
if (flags.strict) {
126131
const outputType = flags.json ? 'json' : 'text'
127132
const {offenses} = await runThemeCheck(flags.path ?? cwd(), outputType)
@@ -156,7 +161,7 @@ export async function push(
156161
return
157162
}
158163

159-
const selectedTheme: Theme | undefined = await createOrSelectTheme(adminSession, flags, multiEnvironment)
164+
const selectedTheme: Theme | undefined = await createOrSelectTheme(session, flags, multiEnvironment)
160165
if (!selectedTheme) {
161166
return
162167
}

0 commit comments

Comments
 (0)