From 8e66e109956f097163af6cb3fa38c74b0593cff5 Mon Sep 17 00:00:00 2001 From: Stevche Radevski Date: Wed, 29 May 2024 10:42:53 +0200 Subject: [PATCH] fix: Use correct config for auth methods per actor (#7515) --- packages/core/types/src/common/config-module.ts | 2 +- .../auth/[actor_type]/[auth_provider]/callback/route.ts | 7 ++++--- .../src/api/auth/[actor_type]/[auth_provider]/route.ts | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/core/types/src/common/config-module.ts b/packages/core/types/src/common/config-module.ts index c29ddba886..e90bc1e617 100644 --- a/packages/core/types/src/common/config-module.ts +++ b/packages/core/types/src/common/config-module.ts @@ -735,7 +735,7 @@ export type ProjectConfigOptions = { * } * ``` */ - authMethodsPerActor: Record + authMethodsPerActor?: Record } } diff --git a/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/callback/route.ts b/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/callback/route.ts index a24d1c91bc..f6bb2e9372 100644 --- a/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/callback/route.ts +++ b/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/callback/route.ts @@ -14,10 +14,11 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => { ContainerRegistrationKeys.CONFIG_MODULE ) - const authMethods = (config.projectConfig?.http as any)?.authMethods ?? {} + const authMethodsPerActor = + config.projectConfig?.http?.authMethodsPerActor ?? {} // Not having the config defined would allow for all auth providers for the particular actor. - if (authMethods[actor_type]) { - if (!authMethods[actor_type].includes(auth_provider)) { + if (authMethodsPerActor[actor_type]) { + if (!authMethodsPerActor[actor_type].includes(auth_provider)) { throw new MedusaError( MedusaError.Types.NOT_ALLOWED, `The actor type ${actor_type} is not allowed to use the auth provider ${auth_provider}` diff --git a/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/route.ts b/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/route.ts index 50590d77ae..9bb8b6b681 100644 --- a/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/route.ts +++ b/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/route.ts @@ -14,10 +14,11 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => { ContainerRegistrationKeys.CONFIG_MODULE ) - const authMethods = (config.projectConfig?.http as any)?.authMethods ?? {} + const authMethodsPerActor = + config.projectConfig?.http?.authMethodsPerActor ?? {} // Not having the config defined would allow for all auth providers for the particular actor. - if (authMethods[actor_type]) { - if (!authMethods[actor_type].includes(auth_provider)) { + if (authMethodsPerActor[actor_type]) { + if (!authMethodsPerActor[actor_type].includes(auth_provider)) { throw new MedusaError( MedusaError.Types.NOT_ALLOWED, `The actor type ${actor_type} is not allowed to use the auth provider ${auth_provider}`