Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Theme Access authentication on shopify theme dev and shopify theme console commands #4490

Merged
merged 1 commit into from
Sep 20, 2024
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
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