Skip to content

Commit

Permalink
Use URL constructor to grab redirect pathname
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmengo committed Nov 28, 2024
1 parent 7017b9e commit 115718c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ describe('Storefront API', () => {
// Then
expect(isProtected).toBe(false)
})

test('ignores query params', async () => {
// Given
vi.mocked(fetch)
.mockResolvedValueOnce(response({status: 200, url: 'https://store.myshopify.com/random?a=b'}))
.mockResolvedValueOnce(response({status: 200, url: 'https://store.myshopify.com/password?a=b'}))

// When
const redirectToRandomPath = await isStorefrontPasswordProtected('store.myshopify.com')
const redirectToPasswordPath = await isStorefrontPasswordProtected('store.myshopify.com')

// Then
expect(redirectToRandomPath).toBe(false)
expect(redirectToPasswordPath).toBe(true)
})
})

describe('getStorefrontSessionCookies', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export async function isStorefrontPasswordProtected(storeURL: string): Promise<b
method: 'GET',
})

return response.url.endsWith('/password')
const redirectLocation = new URL(response.url)
return redirectLocation.pathname.endsWith('/password')
}

/**
Expand Down

0 comments on commit 115718c

Please sign in to comment.