Skip to content

Commit

Permalink
Merge pull request #17 from runyasak/fix/private-api-key
Browse files Browse the repository at this point in the history
fix: move apiKey to private config
  • Loading branch information
Baroshem authored Apr 17, 2023
2 parents 77afe7a + cb7f635 commit 8a8e3d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/content/1.getting-started/2.options.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ When set to `true` it will register Medusa client globally through a plugin. Oth

When set to `true` it will add a server utility `serverMedusaClient` that allows to fetch data from Medusa from server side.

## `apiKey`
## `apiKey` (For server only)

- Optional: `''`

Optional API key used for authenticating admin requests.
Optional API key used for authenticating admin requests, can be done from server or `serverMedusaClient` only.

## `publishableApiKey`

Expand Down
5 changes: 4 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ export default defineNuxtModule<ModuleOptions>({
setup (options, nuxt) {
const resolver = createResolver(import.meta.url)

nuxt.options.runtimeConfig.private = defu(nuxt.options.runtimeConfig.private, {
apiKey: options.apiKey
})

nuxt.options.runtimeConfig.public.medusa = defu(nuxt.options.runtimeConfig.public.medusa, {
baseUrl: process.env.MEDUSA_URL || options.baseUrl,
maxRetries: options.maxRetries,
apiKey: options.apiKey,
publishableApiKey: options.publishableApiKey,
global: options.global
})
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/server/services/serverMedusaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { useRuntimeConfig } from '#imports'
export const serverMedusaClient = (event: H3Event): Medusa => {
const { medusa: config } = useRuntimeConfig().public

const privateConfig = useRuntimeConfig().private

if (!event.context._medusaClient) {
const medusaClient = new Medusa(config)
const medusaClient = new Medusa({ ...config, ...privateConfig })

event.context._medusaClient = medusaClient
}
Expand Down

1 comment on commit 8a8e3d8

@vercel
Copy link

@vercel vercel bot commented on 8a8e3d8 Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nuxt-medusa – ./

nuxt-medusa-baroshem.vercel.app
nuxt-medusa.vercel.app
nuxt-medusa-git-main-baroshem.vercel.app

Please sign in to comment.