mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-22 07:01:07 +03:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user