diff --git a/packages/server/src/enterprise/controllers/login-method.controller.ts b/packages/server/src/enterprise/controllers/login-method.controller.ts index e7c9330f..130e8958 100644 --- a/packages/server/src/enterprise/controllers/login-method.controller.ts +++ b/packages/server/src/enterprise/controllers/login-method.controller.ts @@ -1,16 +1,17 @@ import { NextFunction, Request, Response } from 'express' import { StatusCodes } from 'http-status-codes' -import { LoginMethodErrorMessage, LoginMethodService } from '../services/login-method.service' +import { InternalFlowiseError } from '../../errors/internalFlowiseError' +import { Platform } from '../../Interface' +import { GeneralErrorMessage } from '../../utils/constants' import { getRunningExpressApp } from '../../utils/getRunningExpressApp' import { LoginMethod, LoginMethodStatus } from '../database/entities/login-method.entity' -import { InternalFlowiseError } from '../../errors/internalFlowiseError' -import { decrypt } from '../utils/encryption.util' -import AzureSSO from '../sso/AzureSSO' -import GoogleSSO from '../sso/GoogleSSO' -import Auth0SSO from '../sso/Auth0SSO' +import { LoginMethodErrorMessage, LoginMethodService } from '../services/login-method.service' import { OrganizationService } from '../services/organization.service' -import { Platform } from '../../Interface' +import Auth0SSO from '../sso/Auth0SSO' +import AzureSSO from '../sso/AzureSSO' import GithubSSO from '../sso/GithubSSO' +import GoogleSSO from '../sso/GoogleSSO' +import { decrypt } from '../utils/encryption.util' export class LoginMethodController { public async create(req: Request, res: Response, next: NextFunction) { @@ -82,13 +83,15 @@ export class LoginMethodController { loginMethod = await loginMethodService.readLoginMethodById(query.id, queryRunner) if (!loginMethod) throw new InternalFlowiseError(StatusCodes.NOT_FOUND, LoginMethodErrorMessage.LOGIN_METHOD_NOT_FOUND) loginMethod.config = JSON.parse(await decrypt(loginMethod.config)) - } else { + } else if (query.organizationId) { loginMethod = await loginMethodService.readLoginMethodByOrganizationId(query.organizationId, queryRunner) for (let method of loginMethod) { method.config = JSON.parse(await decrypt(method.config)) } loginMethodConfig.providers = loginMethod + } else { + throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, GeneralErrorMessage.UNHANDLED_EDGE_CASE) } return res.status(StatusCodes.OK).json(loginMethodConfig) } catch (error) {