Skip to content

Commit

Permalink
feat: Move userpass default definition to defineConfig instead of a h…
Browse files Browse the repository at this point in the history
…ard-coded value
  • Loading branch information
sradevski committed Aug 12, 2024
1 parent 6ffe85a commit 02015b8
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 21 deletions.
12 changes: 11 additions & 1 deletion integration-tests/modules/medusa-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 44 additions & 4 deletions packages/core/utils/src/common/__tests__/define-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion packages/core/utils/src/common/define-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export function defineConfig(config: Partial<ConfigModule> = {}): 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,
Expand All @@ -78,6 +77,18 @@ export function defineConfig(config: Partial<ConfigModule> = {}): 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: {
Expand Down
1 change: 0 additions & 1 deletion packages/modules/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 1 addition & 12 deletions packages/modules/auth/src/loaders/providers.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -33,18 +31,9 @@ export default async ({
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
) & { providers: ModuleProvider[] }
>): Promise<void> => {
// 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,
})
}
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 02015b8

Please sign in to comment.