fix: Use correct config for auth methods per actor (#7515)

This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-05-29 10:42:53 +02:00
1 parent 51ea166df2
commit 8e66e10995
3 files changed
+9 -7

No files matched your search

@@ -735,7 +735,7 @@ export type ProjectConfigOptions = {
* } * }
* ``` * ```
*/ */
authMethodsPerActor: Record<string, string[]> authMethodsPerActor?: Record<string, string[]>
} }
} }
@@ -14,10 +14,11 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
ContainerRegistrationKeys.CONFIG_MODULE 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. // Not having the config defined would allow for all auth providers for the particular actor.
if (authMethods[actor_type]) { if (authMethodsPerActor[actor_type]) {
if (!authMethods[actor_type].includes(auth_provider)) { if (!authMethodsPerActor[actor_type].includes(auth_provider)) {
throw new MedusaError( throw new MedusaError(
MedusaError.Types.NOT_ALLOWED, MedusaError.Types.NOT_ALLOWED,
`The actor type ${actor_type} is not allowed to use the auth provider ${auth_provider}` `The actor type ${actor_type} is not allowed to use the auth provider ${auth_provider}`
@@ -14,10 +14,11 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
ContainerRegistrationKeys.CONFIG_MODULE 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. // Not having the config defined would allow for all auth providers for the particular actor.
if (authMethods[actor_type]) { if (authMethodsPerActor[actor_type]) {
if (!authMethods[actor_type].includes(auth_provider)) { if (!authMethodsPerActor[actor_type].includes(auth_provider)) {
throw new MedusaError( throw new MedusaError(
MedusaError.Types.NOT_ALLOWED, MedusaError.Types.NOT_ALLOWED,
`The actor type ${actor_type} is not allowed to use the auth provider ${auth_provider}` `The actor type ${actor_type} is not allowed to use the auth provider ${auth_provider}`