import { capitalize } from '@rocket.chat/tools'; import type { NextFunction, Request, Response } from 'express'; import { settings } from '../../settings'; export const allowPassportOAuthMiddleware = (service: string, isCustomOAuth: boolean = false) => (_req: Request, _res: Response, next: NextFunction) => { const isPassportFlowEnabled = settings.get('Accounts_OAuth_Use_Modern_Flow'); const settingPrefix = `${isCustomOAuth ? 'Accounts_OAuth_Custom-' : 'Accounts_OAuth_'}`; const isOAuthServiceEnabled = settings.get( `${settingPrefix}${service === 'github_enterprise' ? 'GitHub_Enterprise' : capitalize(service)}`, ); if (!isPassportFlowEnabled || !isOAuthServiceEnabled) { next('router'); } else { next(); } };