-
-
Notifications
You must be signed in to change notification settings - Fork 19.8k
Expand file tree
/
Copy pathindex.ts
More file actions
55 lines (44 loc) · 1.49 KB
/
index.ts
File metadata and controls
55 lines (44 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { registerBuiltInAuthPlugins } from "./auth";
import { registerBuiltInStoragePlugins } from "./storage";
import { getAuthPlugin } from "./registry";
import { getConfig } from "@/lib/config";
// Export all types
export * from "./types";
export * from "./registry";
export * from "./widgets";
// Initialize all built-in plugins
let initialized = false;
export function initializePlugins(): void {
if (initialized) return;
registerBuiltInAuthPlugins();
registerBuiltInStoragePlugins();
initialized = true;
}
// Helper to get providers from config (supports both old `provider` and new `providers` array)
function getProviderIds(config: Awaited<ReturnType<typeof getConfig>>): string[] {
if (config.auth.providers && config.auth.providers.length > 0) {
return config.auth.providers;
}
if (config.auth.provider) {
return [config.auth.provider];
}
return ["credentials"];
}
/**
* Get the configured auth plugins based on prompts.config.ts
*/
export async function getConfiguredAuthPlugins() {
initializePlugins();
const config = await getConfig();
const providerIds = getProviderIds(config);
const plugins = providerIds
.map((id) => getAuthPlugin(id))
.filter((p): p is NonNullable<typeof p> => p !== null && p !== undefined);
if (plugins.length === 0) {
throw new Error(
`No auth plugins found for configured providers: ${providerIds.join(", ")}. ` +
`Available plugins: credentials, google, azure, github`
);
}
return plugins;
}