Skip to content

Commit

Permalink
fix(auth): Remove promise options resolution as it is not supported b…
Browse files Browse the repository at this point in the history
…y medusa for now
  • Loading branch information
adrien2p committed Jan 4, 2024
1 parent a05e110 commit 8852c3e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
9 changes: 3 additions & 6 deletions packages/medusa-plugin-auth/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Router[]> {
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<Router[]> {
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':
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa-plugin-auth/src/loaders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
11 changes: 6 additions & 5 deletions packages/medusa-plugin-auth/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export type AuthOptions = AuthProvider & ProviderOptions;

export type AuthOptionsWrapper =
| AuthOptions
| ((configModule?: ConfigModule, container?: MedusaContainer) => PromiseLike<AuthOptions>)
| PromiseLike<AuthOptions>;
| ((configModule?: ConfigModule, container?: MedusaContainer) => AuthOptions);

export type ProviderOptions =
| GoogleAuthOptions
Expand Down Expand Up @@ -61,14 +60,16 @@ export function handleOption(
opt: AuthOptionsWrapper,
configModule?: ConfigModule,
container?: MedusaContainer
): PromiseLike<AuthOptions> {
): 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<AuthOptions>;
}
return Promise.resolve(opt);
return Promise.resolve(opt);*/

return opt;
}

0 comments on commit 8852c3e

Please sign in to comment.