From 8852c3ed9c1038e115c99108068a3582877092d3 Mon Sep 17 00:00:00 2001 From: adrien2p Date: Thu, 4 Jan 2024 11:27:32 +0100 Subject: [PATCH] fix(auth): Remove promise options resolution as it is not supported by medusa for now --- packages/medusa-plugin-auth/src/api/index.ts | 9 +++------ packages/medusa-plugin-auth/src/loaders/index.ts | 2 +- packages/medusa-plugin-auth/src/types/index.ts | 11 ++++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/medusa-plugin-auth/src/api/index.ts b/packages/medusa-plugin-auth/src/api/index.ts index d85e00e..11ca25f 100644 --- a/packages/medusa-plugin-auth/src/api/index.ts +++ b/packages/medusa-plugin-auth/src/api/index.ts @@ -11,20 +11,17 @@ import AzureStrategy from '../auth-strategies/azure-oidc'; import { AuthOptions, AuthOptionsWrapper, handleOption } from '../types'; -export default async function (rootDirectory, pluginOptions: AuthOptions | AuthOptions[]): Promise { +export default function (rootDirectory, pluginOptions: AuthOptions | AuthOptions[]): Router[] { const configModule = loadConfig(rootDirectory); return loadRouters(configModule, pluginOptions); } -async function loadRouters( - configModule: ConfigModule, - options: AuthOptionsWrapper | AuthOptionsWrapper[] -): Promise { +function loadRouters(configModule: ConfigModule, options: AuthOptionsWrapper | AuthOptionsWrapper[]): Router[] { const routers: Router[] = []; const options_ = Array.isArray(options) ? options : [options]; for (const opt of options_) { - const option = await handleOption(opt, configModule); + const option = handleOption(opt, configModule); switch (option.type) { case 'azure_oidc': diff --git a/packages/medusa-plugin-auth/src/loaders/index.ts b/packages/medusa-plugin-auth/src/loaders/index.ts index d4b5094..1632137 100644 --- a/packages/medusa-plugin-auth/src/loaders/index.ts +++ b/packages/medusa-plugin-auth/src/loaders/index.ts @@ -21,7 +21,7 @@ export default async function authStrategiesLoader( } async function handleStrategyLoading(opt: AuthOptionsWrapper, configModule: ConfigModule, container: MedusaContainer) { - const option = await handleOption(opt, configModule, container); + const option = handleOption(opt, configModule, container); switch (option.type) { case 'azure_oidc': diff --git a/packages/medusa-plugin-auth/src/types/index.ts b/packages/medusa-plugin-auth/src/types/index.ts index 7db958a..662c0dd 100644 --- a/packages/medusa-plugin-auth/src/types/index.ts +++ b/packages/medusa-plugin-auth/src/types/index.ts @@ -26,8 +26,7 @@ export type AuthOptions = AuthProvider & ProviderOptions; export type AuthOptionsWrapper = | AuthOptions - | ((configModule?: ConfigModule, container?: MedusaContainer) => PromiseLike) - | PromiseLike; + | ((configModule?: ConfigModule, container?: MedusaContainer) => AuthOptions); export type ProviderOptions = | GoogleAuthOptions @@ -61,14 +60,16 @@ export function handleOption( opt: AuthOptionsWrapper, configModule?: ConfigModule, container?: MedusaContainer -): PromiseLike { +): AuthOptions { if (typeof opt === 'function') { return handleOption(opt(configModule, container), configModule, container); } - if (typeof opt === 'object' && typeof (opt as any).then === 'function') { + /*if (typeof opt === 'object' && typeof (opt as any).then === 'function') { return opt as PromiseLike; } - return Promise.resolve(opt); + return Promise.resolve(opt);*/ + + return opt; }