chore: Move remaining auth methods to plugins (#4900)
* Move Google, Email, and Azure to plugins * Move OIDC provider, remove old loading code * Move AuthLogo to plugin * AuthLogo -> PluginIcon * Lazy load plugin settings
This commit is contained in:
51
app/utils/PluginLoader.ts
Normal file
51
app/utils/PluginLoader.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import React from "react";
|
||||
|
||||
interface Plugin {
|
||||
id: string;
|
||||
config: {
|
||||
name: string;
|
||||
description: string;
|
||||
requiredEnvVars?: string[];
|
||||
};
|
||||
settings: React.FC;
|
||||
icon: React.FC<{ size?: number; fill?: string }>;
|
||||
}
|
||||
|
||||
export default class PluginLoader {
|
||||
private static pluginsCache: { [id: string]: Plugin };
|
||||
|
||||
public static get plugins(): { [id: string]: Plugin } {
|
||||
if (this.pluginsCache) {
|
||||
return this.pluginsCache;
|
||||
}
|
||||
const plugins = {};
|
||||
|
||||
function importAll(r: any, property: string) {
|
||||
Object.keys(r).forEach((key: string) => {
|
||||
const id = key.split("/")[3];
|
||||
plugins[id] = plugins[id] || {
|
||||
id,
|
||||
};
|
||||
plugins[id][property] = r[key].default ?? React.lazy(r[key]);
|
||||
});
|
||||
}
|
||||
|
||||
importAll(
|
||||
import.meta.glob("../../plugins/*/client/Settings.{ts,js,tsx,jsx}"),
|
||||
"settings"
|
||||
);
|
||||
importAll(
|
||||
import.meta.glob("../../plugins/*/client/Icon.{ts,js,tsx,jsx}", {
|
||||
eager: true,
|
||||
}),
|
||||
"icon"
|
||||
);
|
||||
importAll(
|
||||
import.meta.glob("../../plugins/*/plugin.json", { eager: true }),
|
||||
"config"
|
||||
);
|
||||
|
||||
this.pluginsCache = plugins;
|
||||
return plugins;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user