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

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

View File

@@ -735,7 +735,7 @@ export type ProjectConfigOptions = {
* }
* ```
*/
authMethodsPerActor: Record<string, string[]>
authMethodsPerActor?: Record<string, string[]>
}
}

View File

@@ -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}`

View File

@@ -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}`