chore: Configure auth on JS-SDK in dashboard (#14013)

* chore: Use env vars rather than configs

* Create wicked-turkeys-sell.md
This commit is contained in:
Oli Juhl
2025-11-11 11:15:58 +01:00
committed by GitHub
parent 2b6c39535f
commit c93f77d1b2
6 changed files with 35 additions and 5 deletions

View File

@@ -23,6 +23,8 @@ export async function getViteConfig(
const backendUrl = options.backendUrl ?? ""
const storefrontUrl = options.storefrontUrl ?? ""
const authType = process.env.ADMIN_AUTH_TYPE ?? undefined
const jwtTokenStorageKey = process.env.ADMIN_JWT_TOKEN_STORAGE_KEY ?? undefined
const baseConfig: InlineConfig = {
root,
@@ -48,6 +50,8 @@ export async function getViteConfig(
define: {
__BASE__: JSON.stringify(options.path),
__BACKEND_URL__: JSON.stringify(backendUrl),
__AUTH_TYPE__: JSON.stringify(authType),
__JWT_TOKEN_STORAGE_KEY__: JSON.stringify(jwtTokenStorageKey),
__STOREFRONT_URL__: JSON.stringify(storefrontUrl),
},
server: {
@@ -92,7 +96,11 @@ export async function getViteConfig(
// Handle HMR_BIND_HOST after merge to detect conflicts
if (process.env.HMR_BIND_HOST) {
if (finalConfig.server?.hmr && typeof finalConfig.server.hmr === "object" && finalConfig.server.hmr.server) {
if (
finalConfig.server?.hmr &&
typeof finalConfig.server.hmr === "object" &&
finalConfig.server.hmr.server
) {
console.warn(
"HMR_BIND_HOST is set but a custom hmr.server is already configured. HMR_BIND_HOST will be ignored."
)
@@ -103,7 +111,10 @@ export async function getViteConfig(
if (!finalConfig.server) {
finalConfig.server = {}
}
if (!finalConfig.server.hmr || typeof finalConfig.server.hmr !== "object") {
if (
!finalConfig.server.hmr ||
typeof finalConfig.server.hmr !== "object"
) {
finalConfig.server.hmr = {}
}
finalConfig.server.hmr.server = hmrServer

View File

@@ -1,11 +1,14 @@
import Medusa from "@medusajs/js-sdk"
export const backendUrl = __BACKEND_URL__ ?? "/"
const authType = __AUTH_TYPE__ ?? "session"
const jwtTokenStorageKey = __JWT_TOKEN_STORAGE_KEY__ || undefined
export const sdk = new Medusa({
baseUrl: backendUrl,
auth: {
type: "session",
type: authType,
jwtTokenStorageKey
},
})

View File

@@ -16,3 +16,5 @@ interface ImportMeta {
declare const __BACKEND_URL__: string | undefined
declare const __STOREFRONT_URL__: string | undefined
declare const __BASE__: string
declare const __AUTH_TYPE__: "session" | "jwt" | undefined
declare const __JWT_TOKEN_STORAGE_KEY__: string | undefined

View File

@@ -1,8 +1,13 @@
import Medusa from "@medusajs/js-sdk"
const backendUrl = __BACKEND_URL__ ?? "/"
const authType = __AUTH_TYPE__ ?? "session"
const jwtTokenStorageKey = __JWT_TOKEN_STORAGE_KEY__ || undefined
export const sdk = new Medusa({
baseUrl: __BACKEND_URL__ || "/",
baseUrl: backendUrl,
auth: {
type: "session",
type: authType,
jwtTokenStorageKey: jwtTokenStorageKey,
},
})

View File

@@ -1 +1,3 @@
declare const __BACKEND_URL__: string | undefined
declare const __AUTH_TYPE__: "session" | "jwt" | undefined
declare const __JWT_TOKEN_STORAGE_KEY__: string | undefined