Skip to content
Draft
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
29 changes: 26 additions & 3 deletions packages/theme/src/cli/services/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,38 @@ describe('profile', () => {
await expect(result).rejects.toThrow('Bad response: 404: {"error":"Some error message"}')
})

test('throws error when a password is used', async () => {
test('uses Theme Access tokens when a password is provided', async () => {
// Given
vi.mocked(ensureAuthenticatedStorefront).mockResolvedValue('shptka_hello')

// When
await profile(mockAdminSession, themeId, urlPath, true, 'shptka_hello', undefined)

// Then
expect(render).toHaveBeenCalledWith(
expect.objectContaining({
storefrontToken: 'shptka_hello',
}),
expect.any(Object),
)
})

test('throws error when an Admin API token is used', async () => {
// When
const result = profile(mockAdminSession, themeId, urlPath, true, 'shpat_hello', undefined)

// Then
await expect(result).rejects.toThrow(
new AbortError(
'Unable to use Admin API or Theme Access tokens with the profile command',
'You must authenticate manually by not passing the --password flag.',
'Unable to use Admin API tokens with the profile command',
`To use this command with the --password flag you must:

1. Install the Theme Access app on your shop
2. Generate a new password

Alternatively, you can authenticate normally by not passing the --password flag.

Learn more: https://shopify.dev/docs/storefronts/themes/tools/theme-access`,
),
)
})
Expand Down
13 changes: 10 additions & 3 deletions packages/theme/src/cli/services/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ export async function profile(
? await ensureValidPassword(storefrontPassword, adminSession.storeFqdn)
: undefined

if (themeAccessPassword) {
if (themeAccessPassword?.startsWith('shpat_')) {
throw new AbortError(
'Unable to use Admin API or Theme Access tokens with the profile command',
'You must authenticate manually by not passing the --password flag.',
'Unable to use Admin API tokens with the profile command',
`To use this command with the --password flag you must:

1. Install the Theme Access app on your shop
2. Generate a new password

Alternatively, you can authenticate normally by not passing the --password flag.

Learn more: https://shopify.dev/docs/storefronts/themes/tools/theme-access`,
)
}

Expand Down
Loading