This commit is contained in:
MobiDev 2024-04-21 15:13:33 +02:00 committed by GitHub
commit bb950ef671
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 8 deletions

View file

@ -512,4 +512,5 @@ module.exports = {
// server window, displayed on the client.
raw: false,
},
authModule: "local",
};

View file

@ -111,6 +111,7 @@ export type ConfigType = {
ldap: Ldap;
debug: Debug;
themeColor: string;
authModule: string;
};
class Config {

View file

@ -2,6 +2,8 @@ import colors from "chalk";
import Client from "../client";
import ClientManager from "../clientManager";
import log from "../log";
import Auth from "./packages";
import Config from "../config";
export type AuthHandler = (
manager: ClientManager,
@ -35,17 +37,21 @@ const toExport = {
}
// Override default API stubs with exports from first enabled plugin found
const resolvedPlugins = await Promise.all(plugins);
const packagePlugins = [...Auth.packageMap.values()]
.map((packagee) => packagee.auth || [])
.flatMap((item) => item);
for (const {default: plugin} of resolvedPlugins) {
if (plugin.isEnabled()) {
toExport.initialized = true;
const resolvedPlugins = (await Promise.all(plugins))
.map((plugin) => plugin.default)
.concat(packagePlugins);
for (const name in plugin) {
toExport[name] = plugin[name];
}
const plugin = resolvedPlugins.find(
(resolvedPlugin) => resolvedPlugin.moduleName === Config.values.authModule
);
break;
if (plugin) {
for (const name in plugin) {
toExport[name] = plugin[name];
}
}

View file

@ -10,9 +10,17 @@ import inputs from "../inputs";
import fs from "fs";
import Utils from "../../command-line/utils";
import Client from "../../client";
import {AuthHandler} from "../auth";
type Package = {
onServerStart: (packageApis: any) => void;
auth?: [
{
moduleName: string;
auth: AuthHandler;
isEnabled: () => boolean;
}
];
};
const packageMap = new Map<string, Package>();
@ -44,6 +52,7 @@ export default {
getPackage,
loadPackages,
outdated,
packageMap,
};
// TODO: verify binds worked. Used to be 'this' instead of 'packageApis'