diff --git a/src/lib/app.ts b/src/lib/app.ts index 6ae1716e37..36f2f2c19e 100644 --- a/src/lib/app.ts +++ b/src/lib/app.ts @@ -118,12 +118,16 @@ export default async function getApp( } case IAuthType.ENTERPRISE: { app.use(baseUriPath, apiTokenMiddleware(config, services)); - config.authentication.customAuthHandler(app, config, services); + if (config.authentication.customAuthHandler) { + config.authentication.customAuthHandler(app, config, services); + } break; } case IAuthType.HOSTED: { app.use(baseUriPath, apiTokenMiddleware(config, services)); - config.authentication.customAuthHandler(app, config, services); + if (config.authentication.customAuthHandler) { + config.authentication.customAuthHandler(app, config, services); + } break; } case IAuthType.DEMO: { @@ -138,7 +142,9 @@ export default async function getApp( } case IAuthType.CUSTOM: { app.use(baseUriPath, apiTokenMiddleware(config, services)); - config.authentication.customAuthHandler(app, config, services); + if (config.authentication.customAuthHandler) { + config.authentication.customAuthHandler(app, config, services); + } break; } case IAuthType.NONE: { diff --git a/src/lib/default-custom-auth-deny-all.ts b/src/lib/default-custom-auth-deny-all.ts index 2fdbb736b7..8e29bc42c6 100644 --- a/src/lib/default-custom-auth-deny-all.ts +++ b/src/lib/default-custom-auth-deny-all.ts @@ -1,11 +1,11 @@ +import { Express } from 'express'; import { IUnleashConfig } from './types/option'; const customAuthWarning = 'You have to configure a custom authentication middleware. Read https://docs.getunleash.io/docs/reference/deploy/configuring-unleash for more details'; export function defaultCustomAuthDenyAll( - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types - app: any, + app: Express, config: IUnleashConfig, ): void { const logger = config.getLogger('src/lib/app/customAuthHandler'); diff --git a/src/lib/server-impl.ts b/src/lib/server-impl.ts index 5e273dedd4..dd3fe82ec9 100644 --- a/src/lib/server-impl.ts +++ b/src/lib/server-impl.ts @@ -18,6 +18,7 @@ import { IUnleashOptions, IUnleashServices, RoleName, + CustomAuthHandler, } from './types'; import User, { IUser } from './types/user'; @@ -212,4 +213,5 @@ export type { IAuthRequest, IApiRequest, SimpleAuthSettings, + CustomAuthHandler, }; diff --git a/src/lib/types/option.ts b/src/lib/types/option.ts index eccb651d7d..887c88b429 100644 --- a/src/lib/types/option.ts +++ b/src/lib/types/option.ts @@ -1,8 +1,10 @@ +import { Express } from 'express'; import EventEmitter from 'events'; import { LogLevel, LogProvider } from '../logger'; import { ILegacyApiTokenCreate } from './models/api-token'; import { IFlagResolver, IExperimentalOptions, IFlags } from './experimental'; import SMTPTransport from 'nodemailer/lib/smtp-transport'; +import { IUnleashServices } from './services'; export interface ISSLOption { rejectUnauthorized: boolean; @@ -53,10 +55,16 @@ export enum IAuthType { NONE = 'none', } +export type CustomAuthHandler = ( + app: Express, + config: Partial, + services?: IUnleashServices, +) => void; + export interface IAuthOption { enableApiToken: boolean; type: IAuthType; - customAuthHandler?: Function; + customAuthHandler?: CustomAuthHandler; createAdminUser?: boolean; initialAdminUser?: { username: string; diff --git a/src/test/fixtures/fake-user-store.ts b/src/test/fixtures/fake-user-store.ts index 9831044163..bd78c34de0 100644 --- a/src/test/fixtures/fake-user-store.ts +++ b/src/test/fixtures/fake-user-store.ts @@ -47,7 +47,6 @@ class UserStoreMock implements IUserStore { } async insert(user: User): Promise { - // eslint-disable-next-line no-param-reassign user.id = this.idSeq; this.idSeq += 1; this.data.push(user); @@ -55,7 +54,6 @@ class UserStoreMock implements IUserStore { } async update(id: number, user: User): Promise { - // eslint-disable-next-line no-param-reassign this.data = this.data.map((o) => { if (o.id === id) return { ...o, name: user.name }; return o;