fix: Do not show actively disabled auth providers in self-hosted install (#4794)

* fix: Do not show actively disabled auth providers in self-hosted installation

* self review

* Refactor for easier mocking
This commit is contained in:
Tom Moor
2023-01-28 10:02:25 -08:00
committed by GitHub
parent aac495fa58
commit 075555a867
17 changed files with 95 additions and 62 deletions

View File

@@ -1,17 +1,15 @@
import Router from "koa-router";
import { sortBy } from "lodash";
import { signin } from "@shared/utils/urlHelpers";
import { requireDirectory } from "@server/utils/fs";
export type AuthenticationProviderConfig = {
id: string;
name: string;
enabled: boolean;
authUrl: string;
router: Router;
};
const providers: AuthenticationProviderConfig[] = [];
const authenticationProviderConfigs: AuthenticationProviderConfig[] = [];
requireDirectory(__dirname).forEach(([module, id]) => {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'config' does not exist on type 'unknown'... Remove this comment to see the full error message
@@ -34,14 +32,13 @@ requireDirectory(__dirname).forEach(([module, id]) => {
}
if (config && config.enabled) {
providers.push({
authenticationProviderConfigs.push({
id,
name: config.name,
enabled: config.enabled,
authUrl: signin(id),
router,
});
}
});
export default sortBy(providers, "id");
export default sortBy(authenticationProviderConfigs, "id");