From a013c4edc56fd040764ff6c509ada50c545b09a9 Mon Sep 17 00:00:00 2001 From: Stevche Radevski Date: Tue, 13 Aug 2024 11:10:23 +0200 Subject: [PATCH] feat: Move userpass default definition to defineConfig instead of a hard-coded value (#8557) --- .changeset/thick-carpets-battle.md | 7 +++ integration-tests/modules/medusa-config.js | 12 ++++- .../common/__tests__/define-config.spec.ts | 48 +++++++++++++++++-- .../core/utils/src/common/define-config.ts | 13 ++++- packages/modules/auth/package.json | 1 - .../modules/auth/src/loaders/providers.ts | 13 +---- yarn.lock | 3 +- 7 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 .changeset/thick-carpets-battle.md diff --git a/.changeset/thick-carpets-battle.md b/.changeset/thick-carpets-battle.md new file mode 100644 index 0000000000000..4bb4a07a4404b --- /dev/null +++ b/.changeset/thick-carpets-battle.md @@ -0,0 +1,7 @@ +--- +"@medusajs/auth": patch +"@medusajs/utils": patch +"@medusajs/auth-emailpass": patch +--- + +move emailpass to defaultconfig diff --git a/integration-tests/modules/medusa-config.js b/integration-tests/modules/medusa-config.js index 5240705613aaa..28d8858765b71 100644 --- a/integration-tests/modules/medusa-config.js +++ b/integration-tests/modules/medusa-config.js @@ -39,7 +39,17 @@ module.exports = { medusa_v2: enableMedusaV2, }, modules: { - [Modules.AUTH]: true, + [Modules.AUTH]: { + resolve: "@medusajs/auth", + options: { + providers: [ + { + id: "emailpass", + resolve: "@medusajs/auth-emailpass", + }, + ], + }, + }, [Modules.USER]: { scope: "internal", resources: "shared", diff --git a/packages/core/utils/src/common/__tests__/define-config.spec.ts b/packages/core/utils/src/common/__tests__/define-config.spec.ts index b519b29eb80df..2bf50b1068a6e 100644 --- a/packages/core/utils/src/common/__tests__/define-config.spec.ts +++ b/packages/core/utils/src/common/__tests__/define-config.spec.ts @@ -11,7 +11,17 @@ describe("defineConfig", function () { "featureFlags": {}, "modules": { "apiKey": true, - "auth": true, + "auth": { + "options": { + "providers": [ + { + "id": "emailpass", + "resolve": "@medusajs/auth-emailpass", + }, + ], + }, + "resolve": "@medusajs/auth", + }, "cacheService": true, "cart": true, "currency": true, @@ -107,7 +117,17 @@ describe("defineConfig", function () { "featureFlags": {}, "modules": { "apiKey": true, - "auth": true, + "auth": { + "options": { + "providers": [ + { + "id": "emailpass", + "resolve": "@medusajs/auth-emailpass", + }, + ], + }, + "resolve": "@medusajs/auth", + }, "cacheService": true, "cart": true, "currency": true, @@ -206,7 +226,17 @@ describe("defineConfig", function () { "featureFlags": {}, "modules": { "apiKey": true, - "auth": true, + "auth": { + "options": { + "providers": [ + { + "id": "emailpass", + "resolve": "@medusajs/auth-emailpass", + }, + ], + }, + "resolve": "@medusajs/auth", + }, "cacheService": true, "cart": true, "currency": true, @@ -305,7 +335,17 @@ describe("defineConfig", function () { "featureFlags": {}, "modules": { "apiKey": true, - "auth": true, + "auth": { + "options": { + "providers": [ + { + "id": "emailpass", + "resolve": "@medusajs/auth-emailpass", + }, + ], + }, + "resolve": "@medusajs/auth", + }, "cacheService": true, "currency": true, "customer": true, diff --git a/packages/core/utils/src/common/define-config.ts b/packages/core/utils/src/common/define-config.ts index a23a90668fb78..d7410fc95c36c 100644 --- a/packages/core/utils/src/common/define-config.ts +++ b/packages/core/utils/src/common/define-config.ts @@ -61,7 +61,6 @@ export function defineConfig(config: Partial = {}): ConfigModule { const modules: ConfigModule["modules"] = { [Modules.CACHE]: true, [Modules.EVENT_BUS]: true, - [Modules.AUTH]: true, [Modules.WORKFLOW_ENGINE]: true, [Modules.STOCK_LOCATION]: true, [Modules.INVENTORY]: true, @@ -78,6 +77,18 @@ export function defineConfig(config: Partial = {}): ConfigModule { [Modules.CURRENCY]: true, [Modules.PAYMENT]: true, [Modules.ORDER]: true, + [Modules.AUTH]: { + resolve: "@medusajs/auth", + options: { + providers: [ + { + resolve: "@medusajs/auth-emailpass", + id: "emailpass", + }, + ], + }, + }, + [Modules.USER]: { resolve: "@medusajs/user", options: { diff --git a/packages/modules/auth/package.json b/packages/modules/auth/package.json index 5beade0d87033..96ba1b943c9e4 100644 --- a/packages/modules/auth/package.json +++ b/packages/modules/auth/package.json @@ -44,7 +44,6 @@ "typescript": "^5.1.6" }, "dependencies": { - "@medusajs/auth-emailpass": "0.0.1", "@medusajs/modules-sdk": "^1.12.9", "@medusajs/utils": "^1.11.7", "@mikro-orm/core": "5.9.7", diff --git a/packages/modules/auth/src/loaders/providers.ts b/packages/modules/auth/src/loaders/providers.ts index 83fb613f9ebe2..46d967e64236a 100644 --- a/packages/modules/auth/src/loaders/providers.ts +++ b/packages/modules/auth/src/loaders/providers.ts @@ -1,5 +1,3 @@ -import EmailPassProvider from "@medusajs/auth-emailpass" - import { LoaderOptions, ModulesSdkTypes, ModuleProvider } from "@medusajs/types" import { Lifetime, asFunction, asValue } from "awilix" import { moduleProviderLoader } from "@medusajs/modules-sdk" @@ -33,18 +31,9 @@ export default async ({ | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions ) & { providers: ModuleProvider[] } >): Promise => { - // Note: For now we want to inject some providers out of the box - const providerConfig = [ - { - resolve: EmailPassProvider, - id: "emailpass", - }, - ...(options?.providers ?? []), - ] - await moduleProviderLoader({ container, - providers: providerConfig, + providers: options?.providers || [], registerServiceFn: registrationFn, }) } diff --git a/yarn.lock b/yarn.lock index 5f0fd1c31ddd6..1e8212080c224 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4294,7 +4294,7 @@ __metadata: languageName: unknown linkType: soft -"@medusajs/auth-emailpass@0.0.1, @medusajs/auth-emailpass@workspace:packages/modules/providers/auth-emailpass": +"@medusajs/auth-emailpass@workspace:packages/modules/providers/auth-emailpass": version: 0.0.0-use.local resolution: "@medusajs/auth-emailpass@workspace:packages/modules/providers/auth-emailpass" dependencies: @@ -4327,7 +4327,6 @@ __metadata: version: 0.0.0-use.local resolution: "@medusajs/auth@workspace:packages/modules/auth" dependencies: - "@medusajs/auth-emailpass": 0.0.1 "@medusajs/modules-sdk": ^1.12.9 "@medusajs/types": ^1.11.14 "@medusajs/utils": ^1.11.7