feat(medusa-react,medusa-js): Allow custom headers (#4409)
* add support for passing custom headers to backend through medusa-js and medusa-react * switch order of override of headers * Create gentle-teachers-greet.md --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Oliver Windall Juhl
parent
5a4580b6a8
commit
fe25c8a91f
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa-js": patch
|
||||||
|
"medusa-react": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(medusa-react,medusa-js): Allow custom headers
|
||||||
@@ -16,6 +16,7 @@ export interface Config {
|
|||||||
maxRetries: number
|
maxRetries: number
|
||||||
apiKey?: string
|
apiKey?: string
|
||||||
publishableApiKey?: string
|
publishableApiKey?: string
|
||||||
|
customHeaders?: Record<string, any>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RequestOptions {
|
export interface RequestOptions {
|
||||||
@@ -199,6 +200,9 @@ class Client {
|
|||||||
options: RequestOptions = {},
|
options: RequestOptions = {},
|
||||||
customHeaders: Record<string, any> = {}
|
customHeaders: Record<string, any> = {}
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
|
|
||||||
|
customHeaders = { ...this.config.customHeaders, ...customHeaders }
|
||||||
|
|
||||||
const reqOpts = {
|
const reqOpts = {
|
||||||
method,
|
method,
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ interface MedusaProviderProps {
|
|||||||
* available within the request
|
* available within the request
|
||||||
*/
|
*/
|
||||||
publishableApiKey?: string
|
publishableApiKey?: string
|
||||||
|
customHeaders?: Record<string, any>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MedusaProvider = ({
|
export const MedusaProvider = ({
|
||||||
@@ -39,6 +40,7 @@ export const MedusaProvider = ({
|
|||||||
baseUrl,
|
baseUrl,
|
||||||
apiKey,
|
apiKey,
|
||||||
publishableApiKey,
|
publishableApiKey,
|
||||||
|
customHeaders,
|
||||||
children,
|
children,
|
||||||
}: MedusaProviderProps) => {
|
}: MedusaProviderProps) => {
|
||||||
const medusaClient = new Medusa({
|
const medusaClient = new Medusa({
|
||||||
@@ -46,6 +48,7 @@ export const MedusaProvider = ({
|
|||||||
maxRetries: 0,
|
maxRetries: 0,
|
||||||
apiKey,
|
apiKey,
|
||||||
publishableApiKey,
|
publishableApiKey,
|
||||||
|
customHeaders
|
||||||
})
|
})
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider {...queryClientProviderProps}>
|
<QueryClientProvider {...queryClientProviderProps}>
|
||||||
|
|||||||
Reference in New Issue
Block a user