{"record":{"id":"acf42fd1bcac5692","repo":"FlowiseAI/Flowise","slug":"error-chatflowscontroller-deletechatflow-organi","errorCode":null,"errorMessage":"Error: chatflowsController.deleteChatflow - organization ${orgId} not found!","messagePattern":"Error: chatflowsController\\.deleteChatflow - organization (.+?) not found!","errorType":"exception","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/chatflows/index.ts","lineNumber":57,"sourceCode":"                StatusCodes.PRECONDITION_FAILED,\n                `Error: chatflowsController.checkIfChatflowIsValidForUploads - id not provided!`\n            )\n        }\n        const apiResponse = await chatflowsService.checkIfChatflowIsValidForUploads(req.params.id)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n\nconst deleteChatflow = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (typeof req.params === 'undefined' || !req.params.id) {\n            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsController.deleteChatflow - id not provided!`)\n        }\n        const orgId = req.user?.activeOrganizationId\n        if (!orgId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: chatflowsController.deleteChatflow - organization ${orgId} not found!`\n            )\n        }\n        const workspaceId = req.user?.activeWorkspaceId\n        if (!workspaceId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: chatflowsController.deleteChatflow - workspace ${workspaceId} not found!`\n            )\n        }\n        const userPermittedTypes: EnumChatflowType[] = []\n        const permissions = req.user!.permissions\n        if (req.user?.isOrganizationAdmin) {\n            userPermittedTypes.push(EnumChatflowType.CHATFLOW)\n            userPermittedTypes.push(EnumChatflowType.AGENTFLOW)\n            userPermittedTypes.push(EnumChatflowType.MULTIAGENT)\n            userPermittedTypes.push(EnumChatflowType.ASSISTANT)","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/chatflows/index.ts#L39-L75","documentation":"Thrown by deleteChatflow when req.user?.activeOrganizationId is absent, after the id check passed. Returns NOT_FOUND (404) — a misleading code, since the missing value is an auth-context field, not a missing resource. Indicates the user's session/token lacks an org claim.","triggerScenarios":"Authenticated DELETE /api/v1/chatflows/:id where the JWT/session has no activeOrganizationId. Common right after signup before org assignment, or with a token minted pre-multitenancy.","commonSituations":"User account exists but has no organization membership; auth middleware that injects activeOrganizationId did not run or failed silently; legacy token without org claim still in use; test stub omits the field.","solutions":["Decode the caller's JWT and confirm activeOrganizationId is present and valid.","Ensure the user has at least one organization membership; create/assign one if not.","Verify auth middleware populating activeOrganizationId runs on this route before the controller.","Force a re-login / token refresh after org assignment.","Note: status code should arguably be 401/403, not 404 — file an upstream issue."],"exampleFix":"// before: token has no org claim\n// after: ensure user is in an org, then re-issue token\nawait api.post('/auth/login', creds) // token now contains activeOrganizationId\nawait api.delete(`/api/v1/chatflows/${id}`)","handlingStrategy":"validation","validationCode":"function hasOrgClaim(user): boolean {\n  return Boolean(user && (user as any).activeOrganizationId)\n}\nif (!hasOrgClaim(currentUser)) {\n  // ensure org membership / re-login instead of calling delete\n}","typeGuard":"function hasOrgContext(u: unknown): u is { activeOrganizationId: string } {\n  return typeof u === 'object' && u !== null\n    && typeof (u as any).activeOrganizationId === 'string' && (u as any).activeOrganizationId.length > 0\n}","tryCatchPattern":null,"preventionTips":["Ensure every user has at least one organization membership at provisioning time.","Confirm the org-injecting auth middleware runs on delete routes.","Decode the JWT in dev to verify the org claim is present.","Re-login after org/role changes."],"tags":["flowise","express","auth","organization","multitenant","controller"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}