{"record":{"id":"5e310a85dfff10a4","repo":"FlowiseAI/Flowise","slug":"error-credentialscontroller-updatecredential-wo","errorCode":null,"errorMessage":"Error: credentialsController.updateCredential - workspace ${workspaceId} not found!","messagePattern":"Error: credentialsController\\.updateCredential - workspace (.+?) not found!","errorType":"exception","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/credentials/index.ts","lineNumber":121,"sourceCode":"}\n\nconst updateCredential = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (typeof req.params === 'undefined' || !req.params.id) {\n            throw new InternalFlowiseError(\n                StatusCodes.PRECONDITION_FAILED,\n                `Error: credentialsController.updateCredential - id not provided!`\n            )\n        }\n        if (!req.body) {\n            throw new InternalFlowiseError(\n                StatusCodes.PRECONDITION_FAILED,\n                `Error: credentialsController.updateCredential - body not provided!`\n            )\n        }\n        const workspaceId = req.user?.activeWorkspaceId\n        if (!workspaceId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: credentialsController.updateCredential - workspace ${workspaceId} not found!`\n            )\n        }\n        const apiResponse = await credentialsService.updateCredential(req.params.id, req.body, workspaceId)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n\nexport default {\n    createCredential,\n    deleteCredentials,\n    getAllCredentials,\n    getCredentialById,\n    revealCredentialById,\n    updateCredential","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/credentials/index.ts#L103-L139","documentation":"Thrown by updateCredential when req.user.activeWorkspaceId is falsy — the third and last guard in the handler, after id and body. Same auth-claim root cause as 780/781/783/785. Returns HTTP 404.","triggerScenarios":"PUT /api/v1/credentials/:id with a valid id and body, but the JWT/session lacks activeWorkspaceId. Triggered on the credentials edit-save flow when the user's session lost its workspace binding.","commonSituations":"Stale token after workspace reassignment. SSO login that didn't set the workspace claim. OSS-to-enterprise build switch with an old cookie. Test harness using a token without workspace claims.","solutions":["Re-login to obtain a JWT that includes activeWorkspaceId.","Verify the user still belongs to a workspace; restore membership if removed.","Call the workspace-switch endpoint before the update if the user has multiple workspaces.","In tests, set req.user.activeWorkspaceId in the auth stub."],"exampleFix":"// before — stale token reused\nawait api.updateCredential(id, payload)\n\n// after — refresh auth first\nif (!currentUser.activeWorkspaceId) {\n  await reauthenticate()\n}\nawait api.updateCredential(id, payload)","handlingStrategy":"validation","validationCode":"function assertActiveWorkspace(user: unknown): string {\n  const ws = (user as any)?.activeWorkspaceId\n  if (typeof ws !== 'string' || ws.length === 0) {\n    throw new Error('no activeWorkspaceId — re-login required')\n  }\n  return ws\n}\n\nassertActiveWorkspace(currentUser)\nawait api.updateCredential(id, payload)","typeGuard":"function hasActiveWorkspace(u: unknown): u is { activeWorkspaceId: string } {\n  return typeof u === 'object' && u !== null\n    && typeof (u as any).activeWorkspaceId === 'string'\n    && (u as any).activeWorkspaceId.length > 0\n}","tryCatchPattern":"try {\n  await api.updateCredential(id, payload)\n} catch (e) {\n  if (e.status === 404 && /workspace .* not found/.test(e.message)) {\n    await auth.relogin()\n  } else throw e\n}","preventionTips":["Re-mint the JWT whenever the user's workspace set changes (invite accepted, workspace switched).","On the client, validate id, body, and workspace claim together before issuing an update.","In tests, use a shared auth fixture that always sets activeWorkspaceId."],"tags":["auth","session","workspace","credentials","flowise"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}