feat: Flatten the provider config for all modules (#7930)

This commit is contained in:
Stevche Radevski
2024-07-03 16:57:12 +02:00
committed by GitHub
parent b6e4435c23
commit 012a624ee4
24 changed files with 168 additions and 292 deletions
+14 -21
View File
@@ -9,18 +9,19 @@ import {
} from "@types"
const registrationFn = async (klass, container, pluginOptions) => {
Object.entries(pluginOptions.config || []).map(([name, config]) => {
container.register({
[AuthProviderRegistrationPrefix + name]: asFunction(
(cradle) => new klass(cradle, config),
{
lifetime: klass.LIFE_TIME || Lifetime.SINGLETON,
}
),
})
container.registerAdd(AuthIdentifiersRegistrationName, asValue(name))
container.register({
[AuthProviderRegistrationPrefix + pluginOptions.id]: asFunction(
(cradle) => new klass(cradle, pluginOptions.options ?? {}),
{
lifetime: klass.LIFE_TIME || Lifetime.SINGLETON,
}
),
})
container.registerAdd(
AuthIdentifiersRegistrationName,
asValue(pluginOptions.id)
)
}
export default async ({
@@ -32,21 +33,13 @@ export default async ({
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
) & { providers: ModuleProvider[] }
>): Promise<void> => {
// TODO: Temporary settings used by the starter, remove once the auth module is updated
const isLegacyOptions =
options?.providers?.length && !!(options?.providers[0] as any)?.name
// Note: For now we want to inject some providers out of the box
const providerConfig = [
{
resolve: EmailPassProvider,
options: {
config: {
emailpass: {},
},
},
id: "emailpass",
},
...(isLegacyOptions ? [] : options?.providers ?? []),
...(options?.providers ?? []),
]
await moduleProviderLoader({
+8 -6
View File
@@ -19,11 +19,13 @@ export type AuthModuleOptions = Partial<ModuleServiceInitializeOptions> & {
* The module provider to be registered
*/
resolve: string | ModuleProviderExports
options: {
/**
* key value pair of the provider name and the configuration to be passed to the provider constructor
*/
config: Record<string, unknown>
}
/**
* The id of the provider
*/
id: string
/**
* key value pair of the configuration to be passed to the provider constructor
*/
options?: Record<string, unknown>
}[]
}