Files
drop/server/internal/auth/index.ts
Husky 72ae7a2884 Various bug fixes (#102)
* feat: set lang in html head

* fix: add # in front of git ref

* fix: remove unused vars from example env

* fix: package name and license field

* fix: enable sourcemap for client and server

* fix: emojis not showing in prod

this is extremely cursed, but it works

* chore: refactor auth manager

* feat: disable invitations if simple auth disabled

* feat: add drop version to footer

* feat: translate auth endpoints

* chore: move oidc module

* feat: add weekly tasks

enabled object cleanup as weekly task

* feat: add timestamp to task log msgs

* feat: add guard to prevent invalid progress %

* fix: add missing global scope to i18n components

* feat: set base url for i18n

* feat: switch task log to json format

* ci: run ci on develop branch only

* fix: UserWidget text not updating #109

* fix: EXTERNAL_URL being computed at build

* feat: add basic language outlines for translation

* feat: add more english dialects
2025-06-08 13:49:43 +10:00

63 lines
1.5 KiB
TypeScript

import { AuthMec } from "~/prisma/client";
import { OIDCManager } from "./oidc";
class AuthManager {
private authProviders: {
[AuthMec.Simple]: boolean;
[AuthMec.OpenID]: OIDCManager | undefined;
} = {
[AuthMec.Simple]: false,
[AuthMec.OpenID]: undefined,
};
private initFuncs: {
[K in keyof typeof this.authProviders]: () => Promise<unknown>;
} = {
[AuthMec.OpenID]: OIDCManager.prototype.create,
[AuthMec.Simple]: async () => {
const disabled = process.env.DISABLE_SIMPLE_AUTH as string | undefined;
return !disabled;
},
};
constructor() {
console.log("AuthManager initialized");
}
async init() {
for (const [key, init] of Object.entries(this.initFuncs)) {
try {
const object = await init();
if (!object) break;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(this.authProviders as any)[key] = object;
console.log(`enabled auth: ${key}`);
} catch (e) {
console.warn(e);
}
}
// Add every other auth mechanism here, and fall back to simple if none of them are enabled
if (!this.authProviders[AuthMec.OpenID]) {
this.authProviders[AuthMec.Simple] = true;
}
}
getAuthProviders() {
return this.authProviders;
}
getEnabledAuthProviders() {
const authManagers = Object.entries(this.authProviders)
.filter((e) => !!e[1])
.map((e) => e[0]);
return authManagers;
}
}
const authManager = new AuthManager();
export default authManager;
export * from "./passwordHash";