Skip to content

Commit

Permalink
Fix Theme Access authentication on shopify theme dev and `shopify t…
Browse files Browse the repository at this point in the history
…heme console` commands. (#4491)
  • Loading branch information
karreiro authored Sep 20, 2024
1 parent a1fcc90 commit 72859c9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-chefs-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

Fix Theme Access authentication on `shopify theme dev` and `shopify theme console` commands
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ async function fetchDevServerSession(

const session = await ensureAuthenticatedThemes(adminSession.storeFqdn, adminPassword, [])
const storefrontToken = await ensureAuthenticatedStorefront([], adminPassword)
const sessionCookies = await getStorefrontSessionCookies(baseUrl, themeId, storefrontPassword, {})
const sessionCookies = await getStorefrontSessionCookies(baseUrl, themeId, storefrontPassword, {
'X-Shopify-Shop': session.storeFqdn,
'X-Shopify-Access-Token': session.token,
Authorization: `Bearer ${storefrontToken}`,
})

return {
...session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ vi.mock('@shopify/cli-kit/node/http', async () => {
}
})

const successResponse = {ok: true, status: 200, headers: {get: vi.fn()}} as any
const successResponse = {ok: true, status: 200, headers: {get: vi.fn(), delete: vi.fn()}} as any

const session: DevServerSession = {
token: 'admin_token_abc123',
Expand Down Expand Up @@ -50,6 +50,7 @@ describe('render', () => {

// Then
expect(response.status).toEqual(200)
expect(response.headers.delete).toBeCalled()
expect(fetch).toHaveBeenCalledWith(
'https://store.myshopify.com/products/1?_fd=0&pb=0',
expect.objectContaining({
Expand All @@ -74,6 +75,7 @@ describe('render', () => {

// Then
expect(response.status).toEqual(200)
expect(response.headers.delete).toBeCalled()
expect(fetch).toHaveBeenCalledWith(
'https://theme-kit-access.shopifyapps.com/cli/sfr/products/1?_fd=0&pb=0',
expect.objectContaining({
Expand Down Expand Up @@ -109,6 +111,7 @@ describe('render', () => {

// Then
expect(response.status).toEqual(200)
expect(response.headers.delete).toBeCalled()
expect(fetch).toHaveBeenCalledWith(
'https://store.myshopify.com/products/1?_fd=0&pb=0&section_id=sections--1__announcement-bar',
expect.objectContaining({
Expand All @@ -135,6 +138,7 @@ describe('render', () => {

// Then
expect(response.status).toEqual(200)
expect(response.headers.delete).toBeCalled()
expect(fetch).toHaveBeenCalledWith(
'https://store.myshopify.com/products/1?_fd=0&pb=0&app_block_id=00001111222233334444',
expect.objectContaining({
Expand Down Expand Up @@ -162,6 +166,7 @@ describe('render', () => {

// Then
expect(response.status).toEqual(200)
expect(response.headers.delete).toBeCalled()
expect(fetch).toHaveBeenCalledWith(
'https://store.myshopify.com/products/1?_fd=0&pb=0&section_id=sections--1__announcement-bar',
expect.objectContaining({
Expand Down Expand Up @@ -191,6 +196,7 @@ describe('render', () => {

// Then
expect(response.status).toEqual(200)
expect(response.headers.delete).toBeCalled()
expect(fetch).toHaveBeenCalledWith(
'https://store.myshopify.com/products/1?_fd=0&pb=0&value=A&value=B',
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export async function render(session: DevServerSession, context: DevServerRender
const requestId = response.headers.get('x-request-id')
outputDebug(`← ${response.status} (request_id: ${requestId})`)

/**
* Theme Access app requests return the 'application/json' content type.
* However, patched renderings will never patch JSON requests; so we're
* consistently discarding the content type.
*/
response.headers.delete('Content-Type')

return response
}

Expand Down

0 comments on commit 72859c9

Please sign in to comment.