Skip to content

Commit

Permalink
fix: Use the correct header for publishable key (#7492)
Browse files Browse the repository at this point in the history
  • Loading branch information
sradevski authored May 28, 2024
1 parent f8252b3 commit fb16ef4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/core/js-sdk/src/__tests__/client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { http, HttpResponse } from "msw"
import { setupServer } from "msw/node"

import { Client, FetchError } from "../client"
import { Client, FetchError, PUBLISHABLE_KEY_HEADER } from "../client"

const baseUrl = "https://someurl.com"

Expand Down Expand Up @@ -44,7 +44,7 @@ const server = setupServer(
}
}),
http.get(`${baseUrl}/pubkey`, ({ request, params, cookies }) => {
if (request.headers.get("x-medusa-pub-key") === "test-pub-key") {
if (request.headers.get(PUBLISHABLE_KEY_HEADER) === "test-pub-key") {
return HttpResponse.json({
test: "test",
})
Expand Down
6 changes: 4 additions & 2 deletions packages/core/js-sdk/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import qs from "qs"
import { ClientFetch, Config, FetchArgs, FetchInput, Logger } from "./types"

export const PUBLISHABLE_KEY_HEADER = "x-publishable-api-key"

const hasStorage = (storage: "localStorage" | "sessionStorage") => {
if (typeof window !== "undefined") {
return storage in window
Expand Down Expand Up @@ -201,10 +203,10 @@ export class Client {
}

protected getPublishableKeyHeader_ = ():
| { "x-medusa-pub-key": string }
| { [PUBLISHABLE_KEY_HEADER]: string }
| {} => {
return this.config.publishableKey
? { "x-medusa-pub-key": this.config.publishableKey }
? { [PUBLISHABLE_KEY_HEADER]: this.config.publishableKey }
: {}
}

Expand Down

0 comments on commit fb16ef4

Please sign in to comment.