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:
1 parent
2b6c39535f
commit
c93f77d1b2
6 files changed
+35
-5
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/draft-order": patch
|
||||||
|
"@medusajs/admin-bundler": patch
|
||||||
|
"@medusajs/dashboard": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore: Allow injection of our JS-SDK's auth type in dashboard
|
||||||
@@ -23,6 +23,8 @@ export async function getViteConfig(
|
|||||||
|
|
||||||
const backendUrl = options.backendUrl ?? ""
|
const backendUrl = options.backendUrl ?? ""
|
||||||
const storefrontUrl = options.storefrontUrl ?? ""
|
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 = {
|
const baseConfig: InlineConfig = {
|
||||||
root,
|
root,
|
||||||
@@ -48,6 +50,8 @@ export async function getViteConfig(
|
|||||||
define: {
|
define: {
|
||||||
__BASE__: JSON.stringify(options.path),
|
__BASE__: JSON.stringify(options.path),
|
||||||
__BACKEND_URL__: JSON.stringify(backendUrl),
|
__BACKEND_URL__: JSON.stringify(backendUrl),
|
||||||
|
__AUTH_TYPE__: JSON.stringify(authType),
|
||||||
|
__JWT_TOKEN_STORAGE_KEY__: JSON.stringify(jwtTokenStorageKey),
|
||||||
__STOREFRONT_URL__: JSON.stringify(storefrontUrl),
|
__STOREFRONT_URL__: JSON.stringify(storefrontUrl),
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
@@ -92,7 +96,11 @@ export async function getViteConfig(
|
|||||||
|
|
||||||
// Handle HMR_BIND_HOST after merge to detect conflicts
|
// Handle HMR_BIND_HOST after merge to detect conflicts
|
||||||
if (process.env.HMR_BIND_HOST) {
|
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(
|
console.warn(
|
||||||
"HMR_BIND_HOST is set but a custom hmr.server is already configured. HMR_BIND_HOST will be ignored."
|
"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) {
|
if (!finalConfig.server) {
|
||||||
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 = {}
|
||||||
}
|
}
|
||||||
finalConfig.server.hmr.server = hmrServer
|
finalConfig.server.hmr.server = hmrServer
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import Medusa from "@medusajs/js-sdk"
|
import Medusa from "@medusajs/js-sdk"
|
||||||
|
|
||||||
export const backendUrl = __BACKEND_URL__ ?? "/"
|
export const backendUrl = __BACKEND_URL__ ?? "/"
|
||||||
|
const authType = __AUTH_TYPE__ ?? "session"
|
||||||
|
const jwtTokenStorageKey = __JWT_TOKEN_STORAGE_KEY__ || undefined
|
||||||
|
|
||||||
export const sdk = new Medusa({
|
export const sdk = new Medusa({
|
||||||
baseUrl: backendUrl,
|
baseUrl: backendUrl,
|
||||||
auth: {
|
auth: {
|
||||||
type: "session",
|
type: authType,
|
||||||
|
jwtTokenStorageKey
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+2
@@ -16,3 +16,5 @@ interface ImportMeta {
|
|||||||
declare const __BACKEND_URL__: string | undefined
|
declare const __BACKEND_URL__: string | undefined
|
||||||
declare const __STOREFRONT_URL__: string | undefined
|
declare const __STOREFRONT_URL__: string | undefined
|
||||||
declare const __BASE__: string
|
declare const __BASE__: string
|
||||||
|
declare const __AUTH_TYPE__: "session" | "jwt" | undefined
|
||||||
|
declare const __JWT_TOKEN_STORAGE_KEY__: string | undefined
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
import Medusa from "@medusajs/js-sdk"
|
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({
|
export const sdk = new Medusa({
|
||||||
baseUrl: __BACKEND_URL__ || "/",
|
baseUrl: backendUrl,
|
||||||
auth: {
|
auth: {
|
||||||
type: "session",
|
type: authType,
|
||||||
|
jwtTokenStorageKey: jwtTokenStorageKey,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -1 +1,3 @@
|
|||||||
declare const __BACKEND_URL__: string | undefined
|
declare const __BACKEND_URL__: string | undefined
|
||||||
|
declare const __AUTH_TYPE__: "session" | "jwt" | undefined
|
||||||
|
declare const __JWT_TOKEN_STORAGE_KEY__: string | undefined
|
||||||
Reference in new issue
Block a user