fix: Use the correct header for publishable key (#7492)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { http, HttpResponse } from "msw"
|
import { http, HttpResponse } from "msw"
|
||||||
import { setupServer } from "msw/node"
|
import { setupServer } from "msw/node"
|
||||||
|
|
||||||
import { Client, FetchError } from "../client"
|
import { Client, FetchError, PUBLISHABLE_KEY_HEADER } from "../client"
|
||||||
|
|
||||||
const baseUrl = "https://someurl.com"
|
const baseUrl = "https://someurl.com"
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ const server = setupServer(
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
http.get(`${baseUrl}/pubkey`, ({ request, params, cookies }) => {
|
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({
|
return HttpResponse.json({
|
||||||
test: "test",
|
test: "test",
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import qs from "qs"
|
import qs from "qs"
|
||||||
import { ClientFetch, Config, FetchArgs, FetchInput, Logger } from "./types"
|
import { ClientFetch, Config, FetchArgs, FetchInput, Logger } from "./types"
|
||||||
|
|
||||||
|
export const PUBLISHABLE_KEY_HEADER = "x-publishable-api-key"
|
||||||
|
|
||||||
const hasStorage = (storage: "localStorage" | "sessionStorage") => {
|
const hasStorage = (storage: "localStorage" | "sessionStorage") => {
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
return storage in window
|
return storage in window
|
||||||
@@ -201,10 +203,10 @@ export class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected getPublishableKeyHeader_ = ():
|
protected getPublishableKeyHeader_ = ():
|
||||||
| { "x-medusa-pub-key": string }
|
| { [PUBLISHABLE_KEY_HEADER]: string }
|
||||||
| {} => {
|
| {} => {
|
||||||
return this.config.publishableKey
|
return this.config.publishableKey
|
||||||
? { "x-medusa-pub-key": this.config.publishableKey }
|
? { [PUBLISHABLE_KEY_HEADER]: this.config.publishableKey }
|
||||||
: {}
|
: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user