Add organization filtering and error handling to login method controller (#5323)

feat(login-method.controller.ts): add organization filtering and error handling
This commit is contained in:
Yau
2025-10-21 13:33:39 +08:00
committed by GitHub
parent 4111ec31b0
commit bff859520a
@@ -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) {