feat(medusa-js): Register PublishableApiKey (#2616)
**What**
- register a publishable API key through `medusa-js` i.e. define the key that will be sent with each request
**How**
- introduce KeyManager class which is used to share keys between medusa-js objects.
**Usage**
1. Set the key through the `Medusa` config
2. Set the key through `KeyManager` dynamically:
```ts
import { KeyManager } from "medusa-js"
KeyManager.registerPublishableApiKey("pk_123")
```
---
RESOLVES CORE-794
This commit is contained in:
@@ -20,16 +20,30 @@ interface MedusaProviderProps {
|
||||
baseUrl: string
|
||||
queryClientProviderProps: QueryClientProviderProps
|
||||
children: React.ReactNode
|
||||
/**
|
||||
* Authentication token
|
||||
*/
|
||||
apiKey?: string
|
||||
/**
|
||||
* PublishableApiKey identifier that defines the scope of resources
|
||||
* available within the request
|
||||
*/
|
||||
publishableApiKey?: string
|
||||
}
|
||||
|
||||
export const MedusaProvider = ({
|
||||
queryClientProviderProps,
|
||||
baseUrl,
|
||||
apiKey,
|
||||
publishableApiKey,
|
||||
children,
|
||||
}: MedusaProviderProps) => {
|
||||
const medusaClient = new Medusa({ baseUrl, maxRetries: 0, apiKey })
|
||||
const medusaClient = new Medusa({
|
||||
baseUrl,
|
||||
maxRetries: 0,
|
||||
apiKey,
|
||||
publishableApiKey,
|
||||
})
|
||||
return (
|
||||
<QueryClientProvider {...queryClientProviderProps}>
|
||||
<MedusaContext.Provider
|
||||
|
||||
Reference in New Issue
Block a user