diff --git a/.changeset/gentle-teachers-greet.md b/.changeset/gentle-teachers-greet.md new file mode 100644 index 0000000000..0fe506d5f8 --- /dev/null +++ b/.changeset/gentle-teachers-greet.md @@ -0,0 +1,6 @@ +--- +"@medusajs/medusa-js": patch +"medusa-react": patch +--- + +feat(medusa-react,medusa-js): Allow custom headers diff --git a/packages/medusa-js/src/request.ts b/packages/medusa-js/src/request.ts index 20194fd5e4..6c2252bd4c 100644 --- a/packages/medusa-js/src/request.ts +++ b/packages/medusa-js/src/request.ts @@ -16,6 +16,7 @@ export interface Config { maxRetries: number apiKey?: string publishableApiKey?: string + customHeaders?: Record } export interface RequestOptions { @@ -199,6 +200,9 @@ class Client { options: RequestOptions = {}, customHeaders: Record = {} ): Promise { + + customHeaders = { ...this.config.customHeaders, ...customHeaders } + const reqOpts = { method, withCredentials: true, diff --git a/packages/medusa-react/src/contexts/medusa.tsx b/packages/medusa-react/src/contexts/medusa.tsx index a7ad14c776..0cec47ed6f 100644 --- a/packages/medusa-react/src/contexts/medusa.tsx +++ b/packages/medusa-react/src/contexts/medusa.tsx @@ -32,6 +32,7 @@ interface MedusaProviderProps { * available within the request */ publishableApiKey?: string + customHeaders?: Record } export const MedusaProvider = ({ @@ -39,6 +40,7 @@ export const MedusaProvider = ({ baseUrl, apiKey, publishableApiKey, + customHeaders, children, }: MedusaProviderProps) => { const medusaClient = new Medusa({ @@ -46,6 +48,7 @@ export const MedusaProvider = ({ maxRetries: 0, apiKey, publishableApiKey, + customHeaders }) return (